20 #ifndef WINPR_CUSTOM_CRYPTO_H
21 #define WINPR_CUSTOM_CRYPTO_H
23 #include <winpr/winpr.h>
24 #include <winpr/wtypes.h>
26 #include <winpr/error.h>
32 #define WINPR_MD4_DIGEST_LENGTH 16
33 #define WINPR_MD5_DIGEST_LENGTH 16
34 #define WINPR_SHA1_DIGEST_LENGTH 20
35 #define WINPR_SHA224_DIGEST_LENGTH 28
36 #define WINPR_SHA256_DIGEST_LENGTH 32
37 #define WINPR_SHA384_DIGEST_LENGTH 48
38 #define WINPR_SHA512_DIGEST_LENGTH 64
39 #define WINPR_RIPEMD160_DIGEST_LENGTH 20
40 #define WINPR_SHA3_224_DIGEST_LENGTH 28
41 #define WINPR_SHA3_256_DIGEST_LENGTH 32
42 #define WINPR_SHA3_384_DIGEST_LENGTH 48
43 #define WINPR_SHA3_512_DIGEST_LENGTH 64
44 #define WINPR_SHAKE128_DIGEST_LENGTH 16
45 #define WINPR_SHAKE256_DIGEST_LENGTH 32
61 WINPR_MD_RIPEMD160 = 9,
62 WINPR_MD_SHA3_224 = 10,
63 WINPR_MD_SHA3_256 = 11,
64 WINPR_MD_SHA3_384 = 12,
65 WINPR_MD_SHA3_512 = 13,
66 WINPR_MD_SHAKE128 = 14,
67 WINPR_MD_SHAKE256 = 15
70 typedef struct winpr_hmac_ctx_private_st WINPR_HMAC_CTX;
77 WINPR_API WINPR_MD_TYPE winpr_md_type_from_string(
const char* name);
78 WINPR_API
const char* winpr_md_type_to_string(WINPR_MD_TYPE md);
80 WINPR_API
void winpr_HMAC_Free(WINPR_HMAC_CTX* ctx);
82 WINPR_ATTR_MALLOC(winpr_HMAC_Free, 1)
83 WINPR_API WINPR_HMAC_CTX* winpr_HMAC_New(
void);
84 WINPR_API BOOL winpr_HMAC_Init(WINPR_HMAC_CTX* ctx, WINPR_MD_TYPE md, const
void* key,
86 WINPR_API BOOL winpr_HMAC_Update(WINPR_HMAC_CTX* ctx, const
void* input,
size_t ilen);
87 WINPR_API BOOL winpr_HMAC_Final(WINPR_HMAC_CTX* ctx,
void* output,
size_t ilen);
89 WINPR_API BOOL winpr_HMAC(WINPR_MD_TYPE md, const
void* key,
size_t keylen, const
void* input,
90 size_t ilen,
void* output,
size_t olen);
100 typedef struct winpr_digest_ctx_private_st WINPR_DIGEST_CTX;
107 WINPR_API
void winpr_Digest_Free(WINPR_DIGEST_CTX* ctx);
109 WINPR_ATTR_MALLOC(winpr_Digest_Free, 1)
110 WINPR_API WINPR_DIGEST_CTX* winpr_Digest_New(
void);
111 WINPR_API BOOL winpr_Digest_Init_Allow_FIPS(WINPR_DIGEST_CTX* ctx, WINPR_MD_TYPE md);
112 WINPR_API BOOL winpr_Digest_Init(WINPR_DIGEST_CTX* ctx, WINPR_MD_TYPE md);
113 WINPR_API BOOL winpr_Digest_Update(WINPR_DIGEST_CTX* ctx, const
void* input,
size_t ilen);
114 WINPR_API BOOL winpr_Digest_Final(WINPR_DIGEST_CTX* ctx,
void* output,
size_t ilen);
116 WINPR_API BOOL winpr_Digest_Allow_FIPS(WINPR_MD_TYPE md, const
void* input,
size_t ilen,
117 void* output,
size_t olen);
118 WINPR_API BOOL winpr_Digest(WINPR_MD_TYPE md, const
void* input,
size_t ilen,
void* output,
121 WINPR_API BOOL winpr_DigestSign_Init(WINPR_DIGEST_CTX* ctx, WINPR_MD_TYPE md,
void* key);
122 WINPR_API BOOL winpr_DigestSign_Update(WINPR_DIGEST_CTX* ctx, const
void* input,
size_t ilen);
123 WINPR_API BOOL winpr_DigestSign_Final(WINPR_DIGEST_CTX* ctx,
void* output,
size_t* piolen);
138 WINPR_API
int winpr_RAND(
void* output,
size_t len);
139 WINPR_API
int winpr_RAND_pseudo(
void* output,
size_t len);
149 typedef struct winpr_rc4_ctx_private_st WINPR_RC4_CTX;
156 WINPR_API
void winpr_RC4_Free(WINPR_RC4_CTX* ctx);
158 WINPR_ATTR_MALLOC(winpr_RC4_Free, 1)
159 WINPR_API WINPR_RC4_CTX* winpr_RC4_New_Allow_FIPS(const
void* key,
size_t keylen);
161 WINPR_ATTR_MALLOC(winpr_RC4_Free, 1)
162 WINPR_API WINPR_RC4_CTX* winpr_RC4_New(const
void* key,
size_t keylen);
163 WINPR_API BOOL winpr_RC4_Update(WINPR_RC4_CTX* ctx,
size_t length, const
void* input,
174 #define WINPR_AES_BLOCK_SIZE 16
177 #define WINPR_CIPHER_MAX_IV_LENGTH 16u
178 #define WINPR_CIPHER_MAX_KEY_LENGTH 64u
184 } WINPR_CRYPTO_OPERATION;
189 WINPR_CIPHER_NONE = 0,
190 WINPR_CIPHER_NULL = 1,
191 WINPR_CIPHER_AES_128_ECB = 2,
192 WINPR_CIPHER_AES_192_ECB = 3,
193 WINPR_CIPHER_AES_256_ECB = 4,
194 WINPR_CIPHER_AES_128_CBC = 5,
195 WINPR_CIPHER_AES_192_CBC = 6,
196 WINPR_CIPHER_AES_256_CBC = 7,
197 WINPR_CIPHER_AES_128_CFB128 = 8,
198 WINPR_CIPHER_AES_192_CFB128 = 9,
199 WINPR_CIPHER_AES_256_CFB128 = 10,
200 WINPR_CIPHER_AES_128_CTR = 11,
201 WINPR_CIPHER_AES_192_CTR = 12,
202 WINPR_CIPHER_AES_256_CTR = 13,
203 WINPR_CIPHER_AES_128_GCM = 14,
204 WINPR_CIPHER_AES_192_GCM = 15,
205 WINPR_CIPHER_AES_256_GCM = 16,
206 WINPR_CIPHER_CAMELLIA_128_ECB = 17,
207 WINPR_CIPHER_CAMELLIA_192_ECB = 18,
208 WINPR_CIPHER_CAMELLIA_256_ECB = 19,
209 WINPR_CIPHER_CAMELLIA_128_CBC = 20,
210 WINPR_CIPHER_CAMELLIA_192_CBC = 21,
211 WINPR_CIPHER_CAMELLIA_256_CBC = 22,
212 WINPR_CIPHER_CAMELLIA_128_CFB128 = 23,
213 WINPR_CIPHER_CAMELLIA_192_CFB128 = 24,
214 WINPR_CIPHER_CAMELLIA_256_CFB128 = 25,
215 WINPR_CIPHER_CAMELLIA_128_CTR = 26,
216 WINPR_CIPHER_CAMELLIA_192_CTR = 27,
217 WINPR_CIPHER_CAMELLIA_256_CTR = 28,
218 WINPR_CIPHER_CAMELLIA_128_GCM = 29,
219 WINPR_CIPHER_CAMELLIA_192_GCM = 30,
220 WINPR_CIPHER_CAMELLIA_256_GCM = 31,
221 WINPR_CIPHER_DES_ECB = 32,
222 WINPR_CIPHER_DES_CBC = 33,
223 WINPR_CIPHER_DES_EDE_ECB = 34,
224 WINPR_CIPHER_DES_EDE_CBC = 35,
225 WINPR_CIPHER_DES_EDE3_ECB = 36,
226 WINPR_CIPHER_DES_EDE3_CBC = 37,
227 WINPR_CIPHER_BLOWFISH_ECB = 38,
228 WINPR_CIPHER_BLOWFISH_CBC = 39,
229 WINPR_CIPHER_BLOWFISH_CFB64 = 40,
230 WINPR_CIPHER_BLOWFISH_CTR = 41,
231 WINPR_CIPHER_ARC4_128 = 42,
232 WINPR_CIPHER_AES_128_CCM = 43,
233 WINPR_CIPHER_AES_192_CCM = 44,
234 WINPR_CIPHER_AES_256_CCM = 45,
235 WINPR_CIPHER_CAMELLIA_128_CCM = 46,
236 WINPR_CIPHER_CAMELLIA_192_CCM = 47,
237 WINPR_CIPHER_CAMELLIA_256_CCM = 48,
240 typedef struct winpr_cipher_ctx_private_st WINPR_CIPHER_CTX;
254 WINPR_API WINPR_CIPHER_TYPE winpr_cipher_type_from_string(
const char* name);
263 WINPR_API
const char* winpr_cipher_type_to_string(WINPR_CIPHER_TYPE md);
265 WINPR_API
void winpr_Cipher_Free(WINPR_CIPHER_CTX* ctx);
267 WINPR_ATTR_MALLOC(winpr_Cipher_Free, 1)
268 WINPR_API WINPR_DEPRECATED_VAR("[since 3.10.0] use winpr_Cipher_NewEx",
269 WINPR_CIPHER_CTX* winpr_Cipher_New(WINPR_CIPHER_TYPE cipher,
270 WINPR_CRYPTO_OPERATION op,
290 WINPR_ATTR_MALLOC(winpr_Cipher_Free, 1)
291 WINPR_API WINPR_CIPHER_CTX* winpr_Cipher_NewEx(WINPR_CIPHER_TYPE cipher,
292 WINPR_CRYPTO_OPERATION op, const
void* key,
293 size_t keylen, const
void* iv,
size_t ivlen);
294 WINPR_API BOOL winpr_Cipher_SetPadding(WINPR_CIPHER_CTX* ctx, BOOL enabled);
295 WINPR_API BOOL winpr_Cipher_Update(WINPR_CIPHER_CTX* ctx, const
void* input,
size_t ilen,
296 void* output,
size_t* olen);
297 WINPR_API BOOL winpr_Cipher_Final(WINPR_CIPHER_CTX* ctx,
void* output,
size_t* olen);
312 WINPR_API
int winpr_Cipher_BytesToKey(
int cipher, WINPR_MD_TYPE md,
const void* salt,
313 const void* data,
size_t datal,
size_t count,
void* key,