-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpscrypto.h
128 lines (105 loc) · 4.08 KB
/
pscrypto.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef PSCRYPTO_H
#define PSCRYPTO_H
#define _PS_STRINGIZE(S) #S
#define PSCRYPTO_VERSION_MAJOR 1
#define PSCRYPTO_VERSION_MINOR 1
#define PSCRYPTO_VERSION_STRING _PS_STRINGIZE(PSCRYPTO_VERSION_MAJOR) "." _PS_STRINGIZE(PSCRYPTO_VERSION_MINOR)
#ifdef __cplusplus
extern "C" {
#endif
// NOTE: all crypto is 128-bit (16 bytes) which is terrible and pretty much ineffective.
// Version verification
/// Returns initialization status. 1 for okay, 0 for failure
bool PSCrypto_Init(int major, int minor);
/// Returns version numbers
void PSCrypto_Get_Version(int * major, int * minor);
/// Returns version string
const char * PSCrypto_Version_String();
// Diffie-Helman (shared secret agreement)
/**
* Starts a Diffie-Helman key exchange with another party who's P and G values
* are already known.
*
* @param p 16 bytes of P value
* @param g 16 bytes of G value
* @param privKey A generated private key (16 bytes) [out]
* @param pubKey A generated public key (16 bytes) [out]
* @returns Newly created CryptoPP DH object or NULL on failure
*/
DH * DH_Start(const byte * p, const byte * g, byte * privKey, byte * pubKey);
/**
* Starts a new Diffie-Helman key exchange
*
* @param privKey A generated private key (16 bytes) [out]
* @param pubKey A generated public key (16 bytes) [out]
* @param p Generated P value (16 bytes) [out]
* @param g Generated G value (16 bytes) [out]
* @returns Newly created CryptoPP DH object or NULL on failure
*/
DH * DH_Start_Generate(byte * privKey, byte * pubKey, byte * p, byte * g);
/**
* Perform an agreement with another party to come to a shared secret
*
* @param dh A previously created DH object
* @param agreedValue A generated 128-bit shared secret when function returns true [out]
* @param privKey Our private key
* @param otherPubKey The other party's public key
* @returns True on a successful agreement. False on some failure
*/
bool DH_Agree(DH * dh, byte * agreedValue, const byte * privKey, const byte * otherPubKey);
/// Free created DH object
void Free_DH(DH * ptr);
// RC5 (encryption and decryption)
/**
* Initialize an RC5 instance with the specfied key
*
* @param key The input key buffer
* @param keyLen The input key length in bytes
* @param encrypt True for an encryption instance. False for decryption
* @returns A newly created RC5 instance or NULL on failure
*/
void * RC5_Init(byte * key, size_t keyLen, bool encrypt);
/**
* Perform an RC5 decryption
*
* @param dec A previously created RC5 decryption instance
* @param ct A ciphertext buffer
* @param ptLen The length of the ciphertext. Must be aligned to the size of an
* RC5 block (16 bytes)
* @param pt A pointer to a destination plaintext buffer of size ctLen [out]
* @returns True on a successful decryption
*/
bool RC5_Decrypt(RC5::Decryption * dec, byte * ct, size_t ctLen, byte * pt);
/**
* Perform an RC5 encryption
*
* @param enc A previously created RC5 encryption instance
* @param pt A plaintext buffer
* @param ptLen The length of the plaintext. Must be aligned to the size of an
* RC5 block (16 bytes)
* @param ct A pointer to a destination ciphertext buffer of size ptLen [out]
* @returns True on a successful encryption
*/
bool RC5_Encrypt(RC5::Encryption * enc, byte * pt, size_t ptLen, byte * ct);
/// Free a previously created RC5 object
void Free_RC5(RC5 * ptr);
// MD5MAC (packet integrity and authenticity)
/**
* Performs a single MD5 MAC computation
*
* @param key Input key buffer
* @param keyLen Size of the input key buffer
* @param msg Message to create a MAC for
* @param msgLen Length of the message
* @param outBuf Output buffer to receive the MAC value (16 for a full MAC)
* @param outBufLen Output buffer length. If the length is smaller than the size
* of a single MAC, the result will be truncated. If it is
* bigger, multiple MAC values will be concatenated until the
* size is reached.
* @returns Returns true on a successful MAC
*/
bool MD5_MAC(byte * key, size_t keyLen, byte * msg, size_t msgLen, byte * outBuf, size_t outBufLen);
#ifdef __cplusplus
}
#endif
#endif