Unified · Split
| @@ -287,55 +287,22 @@ DEFINE_GCRYPT_WRAPPER(sha256, SHA256) · 286 unmodified lines | |||
| 287 | DEFINE_GCRYPT_WRAPPER(sha512, SHA512) | 287 | DEFINE_GCRYPT_WRAPPER(sha512, SHA512) |
| 288 | DEFINE_GCRYPT_WRAPPER(ripemd160, RMD160) | 288 | DEFINE_GCRYPT_WRAPPER(ripemd160, RMD160) |
| 289 | 289 | ||
| 290 | static void run_gcrypt_aes128(uint8_t *output, | 290 | #define DEFINE_GCRYPT_CYPHER_WRAPPER(suffix, cypher, sz) \ |
| 291 | const uint8_t *input, unsigned size) | 291 | static void run_gcrypt_ ## suffix(uint8_t *output, \ |
| 292 | { | 292 | const uint8_t *input, unsigned size) \ |
| 293 | static gcry_cipher_hd_t aes; | 293 | { \ |
| 294 | if (!aes) | 294 | static gcry_cipher_hd_t suffix; \ |
| 295 | gcry_cipher_open(&aes, GCRY_CIPHER_AES128, GCRY_CIPHER_MODE_ECB, 0); | 295 | if (!suffix) \ |
| 296 | gcry_cipher_setkey(aes, hardcoded_key, 16); | 296 | gcry_cipher_open(&suffix, GCRY_CIPHER_ ## cypher, GCRY_CIPHER_MODE_ECB, 0); \ |
| 297 | gcry_cipher_encrypt(aes, output, size, input, size); | 297 | gcry_cipher_setkey(suffix, hardcoded_key, sz); \ |
| 298 | } | 298 | gcry_cipher_encrypt(suffix, output, size, input, size); \ |
| 299 | 299 | } | |
| 300 | static void run_gcrypt_blowfish(uint8_t *output, | 300 | |
| 301 | const uint8_t *input, unsigned size) | 301 | DEFINE_GCRYPT_CYPHER_WRAPPER(aes128, AES128, 16) |
| 302 | { | 302 | DEFINE_GCRYPT_CYPHER_WRAPPER(blowfish, BLOWFISH, 16) |
| 303 | static gcry_cipher_hd_t blowfish; | 303 | DEFINE_GCRYPT_CYPHER_WRAPPER(camellia, CAMELLIA128, 16) |
| 304 | if (!blowfish) | 304 | DEFINE_GCRYPT_CYPHER_WRAPPER(cast128, CAST5, 16) |
| 305 | gcry_cipher_open(&blowfish, GCRY_CIPHER_BLOWFISH, GCRY_CIPHER_MODE_ECB, 0); | 305 | DEFINE_GCRYPT_CYPHER_WRAPPER(twofish, TWOFISH128, 16) |
| 306 | gcry_cipher_setkey(blowfish, hardcoded_key, 16); | ||
| 307 | gcry_cipher_encrypt(blowfish, output, size, input, size); | ||
| 308 | } | ||
| 309 | |||
| 310 | static void run_gcrypt_camellia(uint8_t *output, | ||
| 311 | const uint8_t *input, unsigned size) | ||
| 312 | { | ||
| 313 | static gcry_cipher_hd_t camellia; | ||
| 314 | if (!camellia) | ||
| 315 | gcry_cipher_open(&camellia, GCRY_CIPHER_CAMELLIA128, GCRY_CIPHER_MODE_ECB, 0); | ||
| 316 | gcry_cipher_setkey(camellia, hardcoded_key, 16); | ||
| 317 | gcry_cipher_encrypt(camellia, output, size, input, size); | ||
| 318 | } | ||
| 319 | |||
| 320 | static void run_gcrypt_cast128(uint8_t *output, | ||
| 321 | const uint8_t *input, unsigned size) | ||
| 322 | { | ||
| 323 | static gcry_cipher_hd_t cast; | ||
| 324 | if (!cast) | ||
| 325 | gcry_cipher_open(&cast, GCRY_CIPHER_CAST5, GCRY_CIPHER_MODE_ECB, 0); | ||
| 326 | gcry_cipher_setkey(cast, hardcoded_key, 16); | ||
| 327 | gcry_cipher_encrypt(cast, output, size, input, size); | ||
| 328 | } | ||
| 329 | |||
| 330 | static void run_gcrypt_twofish(uint8_t *output, | ||
| 331 | const uint8_t *input, unsigned size) | ||
| 332 | { | ||
| 333 | static gcry_cipher_hd_t twofish; | ||
| 334 | if (!twofish) | ||
| 335 | gcry_cipher_open(&twofish, GCRY_CIPHER_TWOFISH128, GCRY_CIPHER_MODE_ECB, 0); | ||
| 336 | gcry_cipher_setkey(twofish, hardcoded_key, 16); | ||
| 337 | gcry_cipher_encrypt(twofish, output, size, input, size); | ||
| 338 | } | ||
| 339 | 306 | ||
| 340 | #define IMPL_USE_gcrypt(...) IMPL_USE(__VA_ARGS__) | 307 | #define IMPL_USE_gcrypt(...) IMPL_USE(__VA_ARGS__) |
| 341 | #else | 308 | #else |