Changeset 745 for trunk/server/source4/heimdal/lib/hcrypto
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 8 deleted
- 32 edited
- 153 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/heimdal/lib/hcrypto/aes.c
r414 r745 120 120 } 121 121 } 122 123 void 124 AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, 125 unsigned long size, const AES_KEY *key, 126 unsigned char *iv, int forward_encrypt) 127 { 128 int i; 129 130 for (i = 0; i < size; i++) { 131 unsigned char tmp[AES_BLOCK_SIZE + 1]; 132 133 memcpy(tmp, iv, AES_BLOCK_SIZE); 134 AES_encrypt(iv, iv, key); 135 if (!forward_encrypt) { 136 tmp[AES_BLOCK_SIZE] = in[i]; 137 } 138 out[i] = in[i] ^ iv[0]; 139 if (forward_encrypt) { 140 tmp[AES_BLOCK_SIZE] = out[i]; 141 } 142 memcpy(iv, &tmp[1], AES_BLOCK_SIZE); 143 } 144 } -
trunk/server/source4/heimdal/lib/hcrypto/aes.h
r414 r745 43 43 #define AES_decrypt hc_AES_decrypt 44 44 #define AES_cbc_encrypt hc_AES_cbc_encrypt 45 #define AES_cfb8_encrypt hc_AES_cfb8_encrypt 45 46 46 47 /* … … 70 71 71 72 void AES_cbc_encrypt(const unsigned char *, unsigned char *, 72 constunsigned long, const AES_KEY *,73 unsigned long, const AES_KEY *, 73 74 unsigned char *, int); 75 void AES_cfb8_encrypt(const unsigned char *, unsigned char *, 76 unsigned long, const AES_KEY *, 77 unsigned char *, int); 74 78 75 79 #ifdef __cplusplus -
trunk/server/source4/heimdal/lib/hcrypto/bn.c
r414 r745 41 41 42 42 #include <krb5-types.h> 43 #include <roken.h> 43 44 #include <rfc2459_asn1.h> /* XXX */ 44 45 #include <der.h> -
trunk/server/source4/heimdal/lib/hcrypto/camellia.h
r414 r745 67 67 68 68 void CAMELLIA_cbc_encrypt(const unsigned char *, unsigned char *, 69 constunsigned long, const CAMELLIA_KEY *,69 unsigned long, const CAMELLIA_KEY *, 70 70 unsigned char *, int); 71 71 -
trunk/server/source4/heimdal/lib/hcrypto/des.c
r414 r745 92 92 #include <krb5-types.h> 93 93 #include <assert.h> 94 95 #include <roken.h> 94 96 95 97 #include "des.h" … … 181 183 DES_is_weak_key(DES_cblock *key) 182 184 { 185 int weak = 0; 183 186 int i; 184 187 185 for (i = 0; i < sizeof(weak_keys)/sizeof(weak_keys[0]); i++) { 186 if (memcmp(weak_keys[i], key, DES_CBLOCK_LEN) == 0) 187 return 1; 188 } 189 return 0; 188 for (i = 0; i < sizeof(weak_keys)/sizeof(weak_keys[0]); i++) 189 weak ^= (ct_memcmp(weak_keys[i], key, DES_CBLOCK_LEN) == 0); 190 191 return !!weak; 190 192 } 191 193 -
trunk/server/source4/heimdal/lib/hcrypto/dh.c
r414 r745 38 38 #include <stdio.h> 39 39 #include <stdlib.h> 40 #include <krb5-types.h> 41 #include <rfc2459_asn1.h> 42 40 43 #include <dh.h> 41 44 … … 302 305 goto out; 303 306 304 if (BN_cmp(bn, pub_key) == 0) {307 if (BN_cmp(bn, dh->g) == 0) { 305 308 unsigned i, n = BN_num_bits(pub_key); 306 309 unsigned bits = 0; … … 310 313 bits++; 311 314 312 if (bits > 1) {315 if (bits < 2) { 313 316 *codes |= DH_CHECK_PUBKEY_TOO_SMALL; 314 317 goto out; … … 443 446 }; 444 447 445 extern const DH_METHOD _hc_dh_ imath_method;446 static const DH_METHOD *dh_default_method = &_hc_dh_ imath_method;448 extern const DH_METHOD _hc_dh_ltm_method; 449 static const DH_METHOD *dh_default_method = &_hc_dh_ltm_method; 447 450 448 451 /** … … 488 491 } 489 492 493 /* 494 * 495 */ 496 497 static int 498 bn2heim_int(BIGNUM *bn, heim_integer *integer) 499 { 500 integer->length = BN_num_bytes(bn); 501 integer->data = malloc(integer->length); 502 if (integer->data == NULL) { 503 integer->length = 0; 504 return ENOMEM; 505 } 506 BN_bn2bin(bn, integer->data); 507 integer->negative = BN_is_negative(bn); 508 return 0; 509 } 510 511 /** 512 * 513 */ 514 515 int 516 i2d_DHparams(DH *dh, unsigned char **pp) 517 { 518 DHParameter data; 519 size_t size; 520 int ret; 521 522 memset(&data, 0, sizeof(data)); 523 524 if (bn2heim_int(dh->p, &data.prime) || 525 bn2heim_int(dh->g, &data.base)) 526 { 527 free_DHParameter(&data); 528 return -1; 529 } 530 531 if (pp == NULL) { 532 size = length_DHParameter(&data); 533 free_DHParameter(&data); 534 } else { 535 void *p; 536 size_t len; 537 538 ASN1_MALLOC_ENCODE(DHParameter, p, len, &data, &size, ret); 539 free_DHParameter(&data); 540 if (ret) 541 return -1; 542 if (len != size) 543 abort(); 544 545 memcpy(*pp, p, size); 546 free(p); 547 548 *pp += size; 549 } 550 551 return size; 552 } -
trunk/server/source4/heimdal/lib/hcrypto/dh.h
r414 r745 41 41 /* symbol renaming */ 42 42 #define DH_null_method hc_DH_null_method 43 #define DH_imath_method hc_DH_imath_method 43 #define DH_tfm_method hc_DH_tfm_method 44 #define DH_ltm_method hc_DH_ltm_method 44 45 #define DH_new hc_DH_new 45 46 #define DH_new_method hc_DH_new_method … … 57 58 #define DH_generate_key hc_DH_generate_key 58 59 #define DH_compute_key hc_DH_compute_key 60 #define i2d_DHparams hc_i2d_DHparams 59 61 60 62 /* … … 115 117 116 118 const DH_METHOD *DH_null_method(void); 117 const DH_METHOD *DH_imath_method(void); 119 const DH_METHOD *DH_tfm_method(void); 120 const DH_METHOD *DH_ltm_method(void); 118 121 119 122 DH * DH_new(void); … … 138 141 int DH_compute_key(unsigned char *,const BIGNUM *,DH *); 139 142 143 int i2d_DHparams(DH *, unsigned char **); 144 140 145 #endif /* _HEIM_DH_H */ 141 146 -
trunk/server/source4/heimdal/lib/hcrypto/engine.c
r414 r745 56 56 const RAND_METHOD *rand; 57 57 }; 58 59 ENGINE * 60 ENGINE_new(void) 61 { 62 ENGINE *engine; 63 64 engine = calloc(1, sizeof(*engine)); 65 engine->references = 1; 66 67 return engine; 68 } 69 70 int 71 ENGINE_free(ENGINE *engine) 72 { 73 return ENGINE_finish(engine); 74 } 58 75 59 76 int … … 196 213 197 214 dup = ENGINE_by_id(engine->id); 198 if (dup) { 199 ENGINE_finish(dup); 215 if (dup) 200 216 return 0; 201 }202 217 203 218 d = realloc(engines, (num_engines + 1) * sizeof(*engines)); … … 216 231 int ret; 217 232 218 engine = calloc(1, sizeof(*engine));233 engine = ENGINE_new(); 219 234 if (engine == NULL) 220 235 return; … … 222 237 ENGINE_set_id(engine, "builtin"); 223 238 ENGINE_set_name(engine, 224 "Heimdal crypto builtin engine version " PACKAGE_VERSION);225 ENGINE_set_RSA(engine, RSA_ imath_method());226 ENGINE_set_DH(engine, DH_ imath_method());239 "Heimdal crypto builtin (ltm) engine version " PACKAGE_VERSION); 240 ENGINE_set_RSA(engine, RSA_ltm_method()); 241 ENGINE_set_DH(engine, DH_ltm_method()); 227 242 228 243 ret = add_engine(engine); 229 244 if (ret != 1) 230 245 ENGINE_finish(engine); 246 247 #ifdef USE_HCRYPTO_TFM 248 /* 249 * TFM 250 */ 251 252 engine = ENGINE_new(); 253 if (engine == NULL) 254 return; 255 256 ENGINE_set_id(engine, "tfm"); 257 ENGINE_set_name(engine, 258 "Heimdal crypto tfm engine version " PACKAGE_VERSION); 259 ENGINE_set_RSA(engine, RSA_tfm_method()); 260 ENGINE_set_DH(engine, DH_tfm_method()); 261 262 ret = add_engine(engine); 263 if (ret != 1) 264 ENGINE_finish(engine); 265 #endif /* USE_HCRYPTO_TFM */ 266 267 #ifdef USE_HCRYPTO_LTM 268 /* 269 * ltm 270 */ 271 272 engine = ENGINE_new(); 273 if (engine == NULL) 274 return; 275 276 ENGINE_set_id(engine, "ltm"); 277 ENGINE_set_name(engine, 278 "Heimdal crypto ltm engine version " PACKAGE_VERSION); 279 ENGINE_set_RSA(engine, RSA_ltm_method()); 280 ENGINE_set_DH(engine, DH_ltm_method()); 281 282 ret = add_engine(engine); 283 if (ret != 1) 284 ENGINE_finish(engine); 285 #endif 286 287 #ifdef HAVE_GMP 288 /* 289 * gmp 290 */ 291 292 engine = ENGINE_new(); 293 if (engine == NULL) 294 return; 295 296 ENGINE_set_id(engine, "gmp"); 297 ENGINE_set_name(engine, 298 "Heimdal crypto gmp engine version " PACKAGE_VERSION); 299 ENGINE_set_RSA(engine, RSA_gmp_method()); 300 301 ret = add_engine(engine); 302 if (ret != 1) 303 ENGINE_finish(engine); 304 #endif 231 305 } 232 306 -
trunk/server/source4/heimdal/lib/hcrypto/engine.h
r414 r745 55 55 #define ENGINE_set_name hc_ENGINE_set_name 56 56 #define ENGINE_set_destroy_function hc_ENGINE_set_destroy_function 57 #define ENGINE_new hc_ENGINE_new 58 #define ENGINE_free hc_ENGINE_free 57 59 #define ENGINE_up_ref hc_ENGINE_up_ref 58 60 #define ENGINE_get_default_DH hc_ENGINE_get_default_DH … … 67 69 typedef struct hc_engine ENGINE; 68 70 71 #define NID_md2 0 72 #define NID_md4 1 73 #define NID_md5 2 74 #define NID_sha1 4 75 #define NID_sha256 5 76 77 /* 78 * 79 */ 80 69 81 #include <hcrypto/rsa.h> 70 82 #include <hcrypto/dsa.h> … … 77 89 typedef unsigned long (*openssl_v_check)(unsigned long); 78 90 91 ENGINE * 92 ENGINE_new(void); 93 int ENGINE_free(ENGINE *); 79 94 void ENGINE_add_conf_module(void); 80 95 void ENGINE_load_builtin_engines(void); -
trunk/server/source4/heimdal/lib/hcrypto/evp-hcrypto.c
r414 r745 43 43 44 44 #include <evp.h> 45 #include <evp-hcrypto.h> 45 46 46 47 #include <krb5-types.h> 47 48 49 #include <des.h> 50 #include "camellia.h" 48 51 #include <aes.h> 52 53 #include <rc2.h> 54 #include <rc4.h> 55 56 #include <sha.h> 57 #include <md2.h> 58 #include <md4.h> 59 #include <md5.h> 49 60 50 61 /* … … 73 84 { 74 85 AES_KEY *k = ctx->cipher_data; 75 AES_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt); 76 return 1; 77 } 78 79 static int 80 aes_cleanup(EVP_CIPHER_CTX *ctx) 81 { 82 memset(ctx->cipher_data, 0, sizeof(AES_KEY)); 86 if (ctx->flags & EVP_CIPH_CFB8_MODE) 87 AES_cfb8_encrypt(in, out, size, k, ctx->iv, ctx->encrypt); 88 else 89 AES_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt); 83 90 return 1; 84 91 } … … 103 110 aes_init, 104 111 aes_do_cipher, 105 aes_cleanup,112 NULL, 106 113 sizeof(AES_KEY), 107 114 NULL, … … 133 140 aes_init, 134 141 aes_do_cipher, 135 aes_cleanup,142 NULL, 136 143 sizeof(AES_KEY), 137 144 NULL, … … 162 169 aes_init, 163 170 aes_do_cipher, 164 aes_cleanup,171 NULL, 165 172 sizeof(AES_KEY), 166 173 NULL, … … 171 178 return &aes_256_cbc; 172 179 } 180 181 /** 182 * The AES-128 CFB8 cipher type (hcrypto) 183 * 184 * @return the AES-128 EVP_CIPHER pointer. 185 * 186 * @ingroup hcrypto_evp 187 */ 188 189 const EVP_CIPHER * 190 EVP_hcrypto_aes_128_cfb8(void) 191 { 192 static const EVP_CIPHER aes_128_cfb8 = { 193 0, 194 1, 195 16, 196 16, 197 EVP_CIPH_CFB8_MODE, 198 aes_init, 199 aes_do_cipher, 200 NULL, 201 sizeof(AES_KEY), 202 NULL, 203 NULL, 204 NULL, 205 NULL 206 }; 207 208 return &aes_128_cfb8; 209 } 210 211 /** 212 * The AES-192 CFB8 cipher type (hcrypto) 213 * 214 * @return the AES-192 EVP_CIPHER pointer. 215 * 216 * @ingroup hcrypto_evp 217 */ 218 219 const EVP_CIPHER * 220 EVP_hcrypto_aes_192_cfb8(void) 221 { 222 static const EVP_CIPHER aes_192_cfb8 = { 223 0, 224 1, 225 24, 226 16, 227 EVP_CIPH_CFB8_MODE, 228 aes_init, 229 aes_do_cipher, 230 NULL, 231 sizeof(AES_KEY), 232 NULL, 233 NULL, 234 NULL, 235 NULL 236 }; 237 return &aes_192_cfb8; 238 } 239 240 /** 241 * The AES-256 CFB8 cipher type (hcrypto) 242 * 243 * @return the AES-256 EVP_CIPHER pointer. 244 * 245 * @ingroup hcrypto_evp 246 */ 247 248 const EVP_CIPHER * 249 EVP_hcrypto_aes_256_cfb8(void) 250 { 251 static const EVP_CIPHER aes_256_cfb8 = { 252 0, 253 1, 254 32, 255 16, 256 EVP_CIPH_CFB8_MODE, 257 aes_init, 258 aes_do_cipher, 259 NULL, 260 sizeof(AES_KEY), 261 NULL, 262 NULL, 263 NULL, 264 NULL 265 }; 266 return &aes_256_cfb8; 267 } 268 269 /** 270 * The message digest SHA256 - hcrypto 271 * 272 * @return the message digest type. 273 * 274 * @ingroup hcrypto_evp 275 */ 276 277 const EVP_MD * 278 EVP_hcrypto_sha256(void) 279 { 280 static const struct hc_evp_md sha256 = { 281 32, 282 64, 283 sizeof(SHA256_CTX), 284 (hc_evp_md_init)SHA256_Init, 285 (hc_evp_md_update)SHA256_Update, 286 (hc_evp_md_final)SHA256_Final, 287 NULL 288 }; 289 return &sha256; 290 } 291 292 /** 293 * The message digest SHA384 - hcrypto 294 * 295 * @return the message digest type. 296 * 297 * @ingroup hcrypto_evp 298 */ 299 300 const EVP_MD * 301 EVP_hcrypto_sha384(void) 302 { 303 static const struct hc_evp_md sha384 = { 304 48, 305 128, 306 sizeof(SHA384_CTX), 307 (hc_evp_md_init)SHA384_Init, 308 (hc_evp_md_update)SHA384_Update, 309 (hc_evp_md_final)SHA384_Final, 310 NULL 311 }; 312 return &sha384; 313 } 314 315 /** 316 * The message digest SHA512 - hcrypto 317 * 318 * @return the message digest type. 319 * 320 * @ingroup hcrypto_evp 321 */ 322 323 const EVP_MD * 324 EVP_hcrypto_sha512(void) 325 { 326 static const struct hc_evp_md sha512 = { 327 64, 328 128, 329 sizeof(SHA512_CTX), 330 (hc_evp_md_init)SHA512_Init, 331 (hc_evp_md_update)SHA512_Update, 332 (hc_evp_md_final)SHA512_Final, 333 NULL 334 }; 335 return &sha512; 336 } 337 338 /** 339 * The message digest SHA1 - hcrypto 340 * 341 * @return the message digest type. 342 * 343 * @ingroup hcrypto_evp 344 */ 345 346 const EVP_MD * 347 EVP_hcrypto_sha1(void) 348 { 349 static const struct hc_evp_md sha1 = { 350 20, 351 64, 352 sizeof(SHA_CTX), 353 (hc_evp_md_init)SHA1_Init, 354 (hc_evp_md_update)SHA1_Update, 355 (hc_evp_md_final)SHA1_Final, 356 NULL 357 }; 358 return &sha1; 359 } 360 361 /** 362 * The message digest MD5 - hcrypto 363 * 364 * @return the message digest type. 365 * 366 * @ingroup hcrypto_evp 367 */ 368 369 const EVP_MD * 370 EVP_hcrypto_md5(void) 371 { 372 static const struct hc_evp_md md5 = { 373 16, 374 64, 375 sizeof(MD5_CTX), 376 (hc_evp_md_init)MD5_Init, 377 (hc_evp_md_update)MD5_Update, 378 (hc_evp_md_final)MD5_Final, 379 NULL 380 }; 381 return &md5; 382 } 383 384 /** 385 * The message digest MD4 - hcrypto 386 * 387 * @return the message digest type. 388 * 389 * @ingroup hcrypto_evp 390 */ 391 392 const EVP_MD * 393 EVP_hcrypto_md4(void) 394 { 395 static const struct hc_evp_md md4 = { 396 16, 397 64, 398 sizeof(MD4_CTX), 399 (hc_evp_md_init)MD4_Init, 400 (hc_evp_md_update)MD4_Update, 401 (hc_evp_md_final)MD4_Final, 402 NULL 403 }; 404 return &md4; 405 } 406 407 /** 408 * The message digest MD2 - hcrypto 409 * 410 * @return the message digest type. 411 * 412 * @ingroup hcrypto_evp 413 */ 414 415 const EVP_MD * 416 EVP_hcrypto_md2(void) 417 { 418 static const struct hc_evp_md md2 = { 419 16, 420 16, 421 sizeof(MD2_CTX), 422 (hc_evp_md_init)MD2_Init, 423 (hc_evp_md_update)MD2_Update, 424 (hc_evp_md_final)MD2_Final, 425 NULL 426 }; 427 return &md2; 428 } 429 430 /* 431 * 432 */ 433 434 static int 435 des_cbc_init(EVP_CIPHER_CTX *ctx, 436 const unsigned char * key, 437 const unsigned char * iv, 438 int encp) 439 { 440 DES_key_schedule *k = ctx->cipher_data; 441 DES_cblock deskey; 442 memcpy(&deskey, key, sizeof(deskey)); 443 DES_set_key_unchecked(&deskey, k); 444 return 1; 445 } 446 447 static int 448 des_cbc_do_cipher(EVP_CIPHER_CTX *ctx, 449 unsigned char *out, 450 const unsigned char *in, 451 unsigned int size) 452 { 453 DES_key_schedule *k = ctx->cipher_data; 454 DES_cbc_encrypt(in, out, size, 455 k, (DES_cblock *)ctx->iv, ctx->encrypt); 456 return 1; 457 } 458 459 /** 460 * The DES cipher type 461 * 462 * @return the DES-CBC EVP_CIPHER pointer. 463 * 464 * @ingroup hcrypto_evp 465 */ 466 467 const EVP_CIPHER * 468 EVP_hcrypto_des_cbc(void) 469 { 470 static const EVP_CIPHER des_cbc = { 471 0, 472 8, 473 8, 474 8, 475 EVP_CIPH_CBC_MODE, 476 des_cbc_init, 477 des_cbc_do_cipher, 478 NULL, 479 sizeof(DES_key_schedule), 480 NULL, 481 NULL, 482 NULL, 483 NULL 484 }; 485 return &des_cbc; 486 } 487 488 /* 489 * 490 */ 491 492 struct des_ede3_cbc { 493 DES_key_schedule ks[3]; 494 }; 495 496 static int 497 des_ede3_cbc_init(EVP_CIPHER_CTX *ctx, 498 const unsigned char * key, 499 const unsigned char * iv, 500 int encp) 501 { 502 struct des_ede3_cbc *k = ctx->cipher_data; 503 DES_cblock deskey; 504 505 memcpy(&deskey, key, sizeof(deskey)); 506 DES_set_odd_parity(&deskey); 507 DES_set_key_unchecked(&deskey, &k->ks[0]); 508 509 memcpy(&deskey, key + 8, sizeof(deskey)); 510 DES_set_odd_parity(&deskey); 511 DES_set_key_unchecked(&deskey, &k->ks[1]); 512 513 memcpy(&deskey, key + 16, sizeof(deskey)); 514 DES_set_odd_parity(&deskey); 515 DES_set_key_unchecked(&deskey, &k->ks[2]); 516 517 return 1; 518 } 519 520 static int 521 des_ede3_cbc_do_cipher(EVP_CIPHER_CTX *ctx, 522 unsigned char *out, 523 const unsigned char *in, 524 unsigned int size) 525 { 526 struct des_ede3_cbc *k = ctx->cipher_data; 527 DES_ede3_cbc_encrypt(in, out, size, 528 &k->ks[0], &k->ks[1], &k->ks[2], 529 (DES_cblock *)ctx->iv, ctx->encrypt); 530 return 1; 531 } 532 533 /** 534 * The tripple DES cipher type - hcrypto 535 * 536 * @return the DES-EDE3-CBC EVP_CIPHER pointer. 537 * 538 * @ingroup hcrypto_evp 539 */ 540 541 const EVP_CIPHER * 542 EVP_hcrypto_des_ede3_cbc(void) 543 { 544 static const EVP_CIPHER des_ede3_cbc = { 545 0, 546 8, 547 24, 548 8, 549 EVP_CIPH_CBC_MODE, 550 des_ede3_cbc_init, 551 des_ede3_cbc_do_cipher, 552 NULL, 553 sizeof(struct des_ede3_cbc), 554 NULL, 555 NULL, 556 NULL, 557 NULL 558 }; 559 return &des_ede3_cbc; 560 } 561 562 /* 563 * 564 */ 565 566 struct rc2_cbc { 567 unsigned int maximum_effective_key; 568 RC2_KEY key; 569 }; 570 571 static int 572 rc2_init(EVP_CIPHER_CTX *ctx, 573 const unsigned char * key, 574 const unsigned char * iv, 575 int encp) 576 { 577 struct rc2_cbc *k = ctx->cipher_data; 578 k->maximum_effective_key = EVP_CIPHER_CTX_key_length(ctx) * 8; 579 RC2_set_key(&k->key, 580 EVP_CIPHER_CTX_key_length(ctx), 581 key, 582 k->maximum_effective_key); 583 return 1; 584 } 585 586 static int 587 rc2_do_cipher(EVP_CIPHER_CTX *ctx, 588 unsigned char *out, 589 const unsigned char *in, 590 unsigned int size) 591 { 592 struct rc2_cbc *k = ctx->cipher_data; 593 RC2_cbc_encrypt(in, out, size, &k->key, ctx->iv, ctx->encrypt); 594 return 1; 595 } 596 597 /** 598 * The RC2 cipher type - hcrypto 599 * 600 * @return the RC2 EVP_CIPHER pointer. 601 * 602 * @ingroup hcrypto_evp 603 */ 604 605 const EVP_CIPHER * 606 EVP_hcrypto_rc2_cbc(void) 607 { 608 static const EVP_CIPHER rc2_cbc = { 609 0, 610 RC2_BLOCK_SIZE, 611 RC2_KEY_LENGTH, 612 RC2_BLOCK_SIZE, 613 EVP_CIPH_CBC_MODE|EVP_CIPH_VARIABLE_LENGTH, 614 rc2_init, 615 rc2_do_cipher, 616 NULL, 617 sizeof(struct rc2_cbc), 618 NULL, 619 NULL, 620 NULL, 621 NULL 622 }; 623 return &rc2_cbc; 624 } 625 626 /** 627 * The RC2-40 cipher type 628 * 629 * @return the RC2-40 EVP_CIPHER pointer. 630 * 631 * @ingroup hcrypto_evp 632 */ 633 634 const EVP_CIPHER * 635 EVP_hcrypto_rc2_40_cbc(void) 636 { 637 static const EVP_CIPHER rc2_40_cbc = { 638 0, 639 RC2_BLOCK_SIZE, 640 5, 641 RC2_BLOCK_SIZE, 642 EVP_CIPH_CBC_MODE, 643 rc2_init, 644 rc2_do_cipher, 645 NULL, 646 sizeof(struct rc2_cbc), 647 NULL, 648 NULL, 649 NULL, 650 NULL 651 }; 652 return &rc2_40_cbc; 653 } 654 655 /** 656 * The RC2-64 cipher type 657 * 658 * @return the RC2-64 EVP_CIPHER pointer. 659 * 660 * @ingroup hcrypto_evp 661 */ 662 663 const EVP_CIPHER * 664 EVP_hcrypto_rc2_64_cbc(void) 665 { 666 static const EVP_CIPHER rc2_64_cbc = { 667 0, 668 RC2_BLOCK_SIZE, 669 8, 670 RC2_BLOCK_SIZE, 671 EVP_CIPH_CBC_MODE, 672 rc2_init, 673 rc2_do_cipher, 674 NULL, 675 sizeof(struct rc2_cbc), 676 NULL, 677 NULL, 678 NULL, 679 NULL 680 }; 681 return &rc2_64_cbc; 682 } 683 684 static int 685 camellia_init(EVP_CIPHER_CTX *ctx, 686 const unsigned char * key, 687 const unsigned char * iv, 688 int encp) 689 { 690 CAMELLIA_KEY *k = ctx->cipher_data; 691 k->bits = ctx->cipher->key_len * 8; 692 CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k); 693 return 1; 694 } 695 696 static int 697 camellia_do_cipher(EVP_CIPHER_CTX *ctx, 698 unsigned char *out, 699 const unsigned char *in, 700 unsigned int size) 701 { 702 CAMELLIA_KEY *k = ctx->cipher_data; 703 CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt); 704 return 1; 705 } 706 707 /** 708 * The Camellia-128 cipher type - hcrypto 709 * 710 * @return the Camellia-128 EVP_CIPHER pointer. 711 * 712 * @ingroup hcrypto_evp 713 */ 714 715 const EVP_CIPHER * 716 EVP_hcrypto_camellia_128_cbc(void) 717 { 718 static const EVP_CIPHER cipher = { 719 0, 720 16, 721 16, 722 16, 723 EVP_CIPH_CBC_MODE, 724 camellia_init, 725 camellia_do_cipher, 726 NULL, 727 sizeof(CAMELLIA_KEY), 728 NULL, 729 NULL, 730 NULL, 731 NULL 732 }; 733 return &cipher; 734 } 735 736 /** 737 * The Camellia-198 cipher type - hcrypto 738 * 739 * @return the Camellia-198 EVP_CIPHER pointer. 740 * 741 * @ingroup hcrypto_evp 742 */ 743 744 const EVP_CIPHER * 745 EVP_hcrypto_camellia_192_cbc(void) 746 { 747 static const EVP_CIPHER cipher = { 748 0, 749 16, 750 24, 751 16, 752 EVP_CIPH_CBC_MODE, 753 camellia_init, 754 camellia_do_cipher, 755 NULL, 756 sizeof(CAMELLIA_KEY), 757 NULL, 758 NULL, 759 NULL, 760 NULL 761 }; 762 return &cipher; 763 } 764 765 /** 766 * The Camellia-256 cipher type - hcrypto 767 * 768 * @return the Camellia-256 EVP_CIPHER pointer. 769 * 770 * @ingroup hcrypto_evp 771 */ 772 773 const EVP_CIPHER * 774 EVP_hcrypto_camellia_256_cbc(void) 775 { 776 static const EVP_CIPHER cipher = { 777 0, 778 16, 779 32, 780 16, 781 EVP_CIPH_CBC_MODE, 782 camellia_init, 783 camellia_do_cipher, 784 NULL, 785 sizeof(CAMELLIA_KEY), 786 NULL, 787 NULL, 788 NULL, 789 NULL 790 }; 791 return &cipher; 792 } 793 794 static int 795 rc4_init(EVP_CIPHER_CTX *ctx, 796 const unsigned char *key, 797 const unsigned char *iv, 798 int enc) 799 { 800 RC4_KEY *k = ctx->cipher_data; 801 RC4_set_key(k, ctx->key_len, key); 802 return 1; 803 } 804 805 static int 806 rc4_do_cipher(EVP_CIPHER_CTX *ctx, 807 unsigned char *out, 808 const unsigned char *in, 809 unsigned int size) 810 { 811 RC4_KEY *k = ctx->cipher_data; 812 RC4(k, size, in, out); 813 return 1; 814 } 815 816 const EVP_CIPHER * 817 EVP_hcrypto_rc4(void) 818 { 819 static const EVP_CIPHER rc4 = { 820 0, 821 1, 822 16, 823 0, 824 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH, 825 rc4_init, 826 rc4_do_cipher, 827 NULL, 828 sizeof(RC4_KEY), 829 NULL, 830 NULL, 831 NULL, 832 NULL 833 }; 834 return &rc4; 835 } 836 837 838 const EVP_CIPHER * 839 EVP_hcrypto_rc4_40(void) 840 { 841 static const EVP_CIPHER rc4_40 = { 842 0, 843 1, 844 5, 845 0, 846 EVP_CIPH_STREAM_CIPHER|EVP_CIPH_VARIABLE_LENGTH, 847 rc4_init, 848 rc4_do_cipher, 849 NULL, 850 sizeof(RC4_KEY), 851 NULL, 852 NULL, 853 NULL, 854 NULL 855 }; 856 return &rc4_40; 857 } -
trunk/server/source4/heimdal/lib/hcrypto/evp.c
r414 r745 46 46 47 47 #include <evp.h> 48 #include <evp-hcrypto.h> 49 #include <evp-cc.h> 48 50 49 51 #include <krb5-types.h> 50 51 #include "camellia.h" 52 #include <des.h> 53 #include <sha.h> 54 #include <rc2.h> 55 #include <rc4.h> 56 #include <md2.h> 57 #include <md4.h> 58 #include <md5.h> 52 #include <roken.h> 53 54 #ifndef HCRYPTO_DEF_PROVIDER 55 #define HCRYPTO_DEF_PROVIDER hcrypto 56 #endif 57 58 #define HC_CONCAT4(x,y,z,aa) x ## y ## z ## aa 59 60 61 #define EVP_DEF_OP(_prov,_op) HC_CONCAT4(EVP_,_prov,_,_op)() 59 62 60 63 /** … … 139 142 */ 140 143 141 void HC_DEPRECATED142 EVP_MD_CTX_init(EVP_MD_CTX *ctx) 144 void 145 EVP_MD_CTX_init(EVP_MD_CTX *ctx) HC_DEPRECATED 143 146 { 144 147 memset(ctx, 0, sizeof(*ctx)); … … 170 173 */ 171 174 172 int HC_DEPRECATED173 EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) 175 int 176 EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) HC_DEPRECATED 174 177 { 175 178 if (ctx->md && ctx->md->cleanup) 176 179 (ctx->md->cleanup)(ctx); 180 else if (ctx->md) 181 memset(ctx->ptr, 0, ctx->md->ctx_size); 177 182 ctx->md = NULL; 178 183 ctx->engine = NULL; … … 352 357 EVP_sha256(void) 353 358 { 354 static const struct hc_evp_md sha256 = { 355 32, 356 64, 357 sizeof(SHA256_CTX), 358 (hc_evp_md_init)SHA256_Init, 359 (hc_evp_md_update)SHA256_Update, 360 (hc_evp_md_final)SHA256_Final, 361 NULL 362 }; 363 return &sha256; 364 } 365 366 static const struct hc_evp_md sha1 = { 367 20, 368 64, 369 sizeof(SHA_CTX), 370 (hc_evp_md_init)SHA1_Init, 371 (hc_evp_md_update)SHA1_Update, 372 (hc_evp_md_final)SHA1_Final, 373 NULL 374 }; 359 hcrypto_validate(); 360 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha256); 361 } 362 363 /** 364 * The message digest SHA384 365 * 366 * @return the message digest type. 367 * 368 * @ingroup hcrypto_evp 369 */ 370 371 const EVP_MD * 372 EVP_sha384(void) 373 { 374 hcrypto_validate(); 375 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha384); 376 } 377 378 /** 379 * The message digest SHA512 380 * 381 * @return the message digest type. 382 * 383 * @ingroup hcrypto_evp 384 */ 385 386 const EVP_MD * 387 EVP_sha512(void) 388 { 389 hcrypto_validate(); 390 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha512); 391 } 375 392 376 393 /** … … 385 402 EVP_sha1(void) 386 403 { 387 return &sha1; 404 hcrypto_validate(); 405 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, sha1); 388 406 } 389 407 … … 397 415 398 416 const EVP_MD * 399 EVP_sha(void) 400 { 401 return &sha1; 417 EVP_sha(void) HC_DEPRECATED 418 419 { 420 hcrypto_validate(); 421 return EVP_sha1(); 402 422 } 403 423 … … 411 431 412 432 const EVP_MD * 413 EVP_md5(void) 414 { 415 static const struct hc_evp_md md5 = { 416 16, 417 64, 418 sizeof(MD5_CTX), 419 (hc_evp_md_init)MD5_Init, 420 (hc_evp_md_update)MD5_Update, 421 (hc_evp_md_final)MD5_Final, 422 NULL 423 }; 424 return &md5; 433 EVP_md5(void) HC_DEPRECATED_CRYPTO 434 { 435 hcrypto_validate(); 436 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md5); 425 437 } 426 438 … … 434 446 435 447 const EVP_MD * 436 EVP_md4(void) 437 { 438 static const struct hc_evp_md md4 = { 439 16, 440 64, 441 sizeof(MD4_CTX), 442 (hc_evp_md_init)MD4_Init, 443 (hc_evp_md_update)MD4_Update, 444 (hc_evp_md_final)MD4_Final, 445 NULL 446 }; 447 return &md4; 448 EVP_md4(void) HC_DEPRECATED_CRYPTO 449 { 450 hcrypto_validate(); 451 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md4); 448 452 } 449 453 … … 457 461 458 462 const EVP_MD * 459 EVP_md2(void) 460 { 461 static const struct hc_evp_md md2 = { 462 16, 463 16, 464 sizeof(MD2_CTX), 465 (hc_evp_md_init)MD2_Init, 466 (hc_evp_md_update)MD2_Update, 467 (hc_evp_md_final)MD2_Final, 468 NULL 469 }; 470 return &md2; 463 EVP_md2(void) HC_DEPRECATED_CRYPTO 464 { 465 hcrypto_validate(); 466 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, md2); 471 467 } 472 468 … … 590 586 c->cipher->cleanup(c); 591 587 if (c->cipher_data) { 588 memset(c->cipher_data, 0, c->cipher->ctx_size); 592 589 free(c->cipher_data); 593 590 c->cipher_data = NULL; … … 596 593 } 597 594 595 /** 596 * If the cipher type supports it, change the key length 597 * 598 * @param c the cipher context to change the key length for 599 * @param length new key length 600 * 601 * @return 1 on success. 602 * 603 * @ingroup hcrypto_evp 604 */ 605 606 int 607 EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int length) 608 { 609 if ((c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH) && length > 0) { 610 c->key_len = length; 611 return 1; 612 } 613 return 0; 614 } 615 598 616 #if 0 599 int600 EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, int length)601 {602 return 0;603 }604 605 617 int 606 618 EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad) … … 769 781 ctx->key_len = c->key_len; 770 782 771 ctx->cipher_data = malloc(c->ctx_size);783 ctx->cipher_data = calloc(1, c->ctx_size); 772 784 if (ctx->cipher_data == NULL && c->ctx_size != 0) 773 785 return 0; … … 781 793 } 782 794 783 switch (EVP_CIPHER_CTX_ flags(ctx)) {795 switch (EVP_CIPHER_CTX_mode(ctx)) { 784 796 case EVP_CIPH_CBC_MODE: 785 797 … … 790 802 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); 791 803 break; 804 805 case EVP_CIPH_STREAM_CIPHER: 806 break; 807 case EVP_CIPH_CFB8_MODE: 808 if (iv) 809 memcpy(ctx->iv, iv, EVP_CIPHER_CTX_iv_length(ctx)); 810 break; 811 792 812 default: 793 813 return 0; … … 1006 1026 } 1007 1027 1008 /*1009 *1010 */1011 1012 struct rc2_cbc {1013 unsigned int maximum_effective_key;1014 RC2_KEY key;1015 };1016 1017 static int1018 rc2_init(EVP_CIPHER_CTX *ctx,1019 const unsigned char * key,1020 const unsigned char * iv,1021 int encp)1022 {1023 struct rc2_cbc *k = ctx->cipher_data;1024 k->maximum_effective_key = EVP_CIPHER_CTX_key_length(ctx) * 8;1025 RC2_set_key(&k->key,1026 EVP_CIPHER_CTX_key_length(ctx),1027 key,1028 k->maximum_effective_key);1029 return 1;1030 }1031 1032 static int1033 rc2_do_cipher(EVP_CIPHER_CTX *ctx,1034 unsigned char *out,1035 const unsigned char *in,1036 unsigned int size)1037 {1038 struct rc2_cbc *k = ctx->cipher_data;1039 RC2_cbc_encrypt(in, out, size, &k->key, ctx->iv, ctx->encrypt);1040 return 1;1041 }1042 1043 static int1044 rc2_cleanup(EVP_CIPHER_CTX *ctx)1045 {1046 memset(ctx->cipher_data, 0, sizeof(struct rc2_cbc));1047 return 1;1048 }1049 1050 1028 /** 1051 1029 * The RC2 cipher type … … 1059 1037 EVP_rc2_cbc(void) 1060 1038 { 1061 static const EVP_CIPHER rc2_cbc = { 1062 0, 1063 RC2_BLOCK_SIZE, 1064 RC2_KEY_LENGTH, 1065 RC2_BLOCK_SIZE, 1066 EVP_CIPH_CBC_MODE, 1067 rc2_init, 1068 rc2_do_cipher, 1069 rc2_cleanup, 1070 sizeof(struct rc2_cbc), 1071 NULL, 1072 NULL, 1073 NULL, 1074 NULL 1075 }; 1076 return &rc2_cbc; 1077 } 1078 1079 /** 1080 * The RC2-40 cipher type 1081 * 1082 * @return the RC2-40 EVP_CIPHER pointer. 1039 hcrypto_validate(); 1040 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_cbc); 1041 } 1042 1043 /** 1044 * The RC2 cipher type 1045 * 1046 * @return the RC2 EVP_CIPHER pointer. 1083 1047 * 1084 1048 * @ingroup hcrypto_evp … … 1088 1052 EVP_rc2_40_cbc(void) 1089 1053 { 1090 static const EVP_CIPHER rc2_40_cbc = { 1091 0, 1092 RC2_BLOCK_SIZE, 1093 5, 1094 RC2_BLOCK_SIZE, 1095 EVP_CIPH_CBC_MODE, 1096 rc2_init, 1097 rc2_do_cipher, 1098 rc2_cleanup, 1099 sizeof(struct rc2_cbc), 1100 NULL, 1101 NULL, 1102 NULL, 1103 NULL 1104 }; 1105 return &rc2_40_cbc; 1106 } 1107 1108 /** 1109 * The RC2-64 cipher type 1110 * 1111 * @return the RC2-64 EVP_CIPHER pointer. 1054 hcrypto_validate(); 1055 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_40_cbc); 1056 } 1057 1058 /** 1059 * The RC2 cipher type 1060 * 1061 * @return the RC2 EVP_CIPHER pointer. 1112 1062 * 1113 1063 * @ingroup hcrypto_evp … … 1117 1067 EVP_rc2_64_cbc(void) 1118 1068 { 1119 static const EVP_CIPHER rc2_64_cbc = { 1120 0, 1121 RC2_BLOCK_SIZE, 1122 8, 1123 RC2_BLOCK_SIZE, 1124 EVP_CIPH_CBC_MODE, 1125 rc2_init, 1126 rc2_do_cipher, 1127 rc2_cleanup, 1128 sizeof(struct rc2_cbc), 1129 NULL, 1130 NULL, 1131 NULL, 1132 NULL 1133 }; 1134 return &rc2_64_cbc; 1069 hcrypto_validate(); 1070 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc2_64_cbc); 1135 1071 } 1136 1072 … … 1146 1082 EVP_rc4(void) 1147 1083 { 1148 printf("evp rc4\n"); 1149 abort(); 1150 return NULL; 1084 hcrypto_validate(); 1085 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc4); 1151 1086 } 1152 1087 … … 1162 1097 EVP_rc4_40(void) 1163 1098 { 1164 printf("evp rc4_40\n"); 1165 abort(); 1166 return NULL; 1167 } 1168 1169 /* 1170 * 1171 */ 1172 1173 static int 1174 des_cbc_init(EVP_CIPHER_CTX *ctx, 1175 const unsigned char * key, 1176 const unsigned char * iv, 1177 int encp) 1178 { 1179 DES_key_schedule *k = ctx->cipher_data; 1180 DES_cblock deskey; 1181 memcpy(&deskey, key, sizeof(deskey)); 1182 DES_set_key_unchecked(&deskey, k); 1183 return 1; 1184 } 1185 1186 static int 1187 des_cbc_do_cipher(EVP_CIPHER_CTX *ctx, 1188 unsigned char *out, 1189 const unsigned char *in, 1190 unsigned int size) 1191 { 1192 DES_key_schedule *k = ctx->cipher_data; 1193 DES_cbc_encrypt(in, out, size, 1194 k, (DES_cblock *)ctx->iv, ctx->encrypt); 1195 return 1; 1196 } 1197 1198 static int 1199 des_cbc_cleanup(EVP_CIPHER_CTX *ctx) 1200 { 1201 memset(ctx->cipher_data, 0, sizeof(struct DES_key_schedule)); 1202 return 1; 1099 hcrypto_validate(); 1100 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, rc4_40); 1203 1101 } 1204 1102 … … 1214 1112 EVP_des_cbc(void) 1215 1113 { 1216 static const EVP_CIPHER des_ede3_cbc = { 1217 0, 1218 8, 1219 8, 1220 8, 1221 EVP_CIPH_CBC_MODE, 1222 des_cbc_init, 1223 des_cbc_do_cipher, 1224 des_cbc_cleanup, 1225 sizeof(DES_key_schedule), 1226 NULL, 1227 NULL, 1228 NULL, 1229 NULL 1230 }; 1231 return &des_ede3_cbc; 1232 } 1233 1234 /* 1235 * 1236 */ 1237 1238 struct des_ede3_cbc { 1239 DES_key_schedule ks[3]; 1240 }; 1241 1242 static int 1243 des_ede3_cbc_init(EVP_CIPHER_CTX *ctx, 1244 const unsigned char * key, 1245 const unsigned char * iv, 1246 int encp) 1247 { 1248 struct des_ede3_cbc *k = ctx->cipher_data; 1249 DES_cblock deskey; 1250 1251 memcpy(&deskey, key, sizeof(deskey)); 1252 DES_set_odd_parity(&deskey); 1253 DES_set_key_unchecked(&deskey, &k->ks[0]); 1254 1255 memcpy(&deskey, key + 8, sizeof(deskey)); 1256 DES_set_odd_parity(&deskey); 1257 DES_set_key_unchecked(&deskey, &k->ks[1]); 1258 1259 memcpy(&deskey, key + 16, sizeof(deskey)); 1260 DES_set_odd_parity(&deskey); 1261 DES_set_key_unchecked(&deskey, &k->ks[2]); 1262 1263 return 1; 1264 } 1265 1266 static int 1267 des_ede3_cbc_do_cipher(EVP_CIPHER_CTX *ctx, 1268 unsigned char *out, 1269 const unsigned char *in, 1270 unsigned int size) 1271 { 1272 struct des_ede3_cbc *k = ctx->cipher_data; 1273 DES_ede3_cbc_encrypt(in, out, size, 1274 &k->ks[0], &k->ks[1], &k->ks[2], 1275 (DES_cblock *)ctx->iv, ctx->encrypt); 1276 return 1; 1277 } 1278 1279 static int 1280 des_ede3_cbc_cleanup(EVP_CIPHER_CTX *ctx) 1281 { 1282 memset(ctx->cipher_data, 0, sizeof(struct des_ede3_cbc)); 1283 return 1; 1114 hcrypto_validate(); 1115 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, des_cbc); 1284 1116 } 1285 1117 … … 1295 1127 EVP_des_ede3_cbc(void) 1296 1128 { 1297 static const EVP_CIPHER des_ede3_cbc = { 1298 0, 1299 8, 1300 24, 1301 8, 1302 EVP_CIPH_CBC_MODE, 1303 des_ede3_cbc_init, 1304 des_ede3_cbc_do_cipher, 1305 des_ede3_cbc_cleanup, 1306 sizeof(struct des_ede3_cbc), 1307 NULL, 1308 NULL, 1309 NULL, 1310 NULL 1311 }; 1312 return &des_ede3_cbc; 1129 hcrypto_validate(); 1130 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, des_ede3_cbc); 1313 1131 } 1314 1132 … … 1324 1142 EVP_aes_128_cbc(void) 1325 1143 { 1326 return EVP_hcrypto_aes_128_cbc(); 1144 hcrypto_validate(); 1145 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_128_cbc); 1327 1146 } 1328 1147 … … 1338 1157 EVP_aes_192_cbc(void) 1339 1158 { 1340 return EVP_hcrypto_aes_192_cbc(); 1159 hcrypto_validate(); 1160 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_192_cbc); 1341 1161 } 1342 1162 … … 1352 1172 EVP_aes_256_cbc(void) 1353 1173 { 1354 return EVP_hcrypto_aes_256_cbc(); 1355 } 1356 1357 static int 1358 camellia_init(EVP_CIPHER_CTX *ctx, 1359 const unsigned char * key, 1360 const unsigned char * iv, 1361 int encp) 1362 { 1363 CAMELLIA_KEY *k = ctx->cipher_data; 1364 k->bits = ctx->cipher->key_len * 8; 1365 CAMELLIA_set_key(key, ctx->cipher->key_len * 8, k); 1366 return 1; 1367 } 1368 1369 static int 1370 camellia_do_cipher(EVP_CIPHER_CTX *ctx, 1371 unsigned char *out, 1372 const unsigned char *in, 1373 unsigned int size) 1374 { 1375 CAMELLIA_KEY *k = ctx->cipher_data; 1376 CAMELLIA_cbc_encrypt(in, out, size, k, ctx->iv, ctx->encrypt); 1377 return 1; 1378 } 1379 1380 static int 1381 camellia_cleanup(EVP_CIPHER_CTX *ctx) 1382 { 1383 memset(ctx->cipher_data, 0, sizeof(CAMELLIA_KEY)); 1384 return 1; 1174 hcrypto_validate(); 1175 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_256_cbc); 1176 } 1177 1178 /** 1179 * The AES-128 cipher type 1180 * 1181 * @return the AES-128 EVP_CIPHER pointer. 1182 * 1183 * @ingroup hcrypto_evp 1184 */ 1185 1186 const EVP_CIPHER * 1187 EVP_aes_128_cfb8(void) 1188 { 1189 hcrypto_validate(); 1190 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_128_cfb8); 1191 } 1192 1193 /** 1194 * The AES-192 cipher type 1195 * 1196 * @return the AES-192 EVP_CIPHER pointer. 1197 * 1198 * @ingroup hcrypto_evp 1199 */ 1200 1201 const EVP_CIPHER * 1202 EVP_aes_192_cfb8(void) 1203 { 1204 hcrypto_validate(); 1205 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_192_cfb8); 1206 } 1207 1208 /** 1209 * The AES-256 cipher type 1210 * 1211 * @return the AES-256 EVP_CIPHER pointer. 1212 * 1213 * @ingroup hcrypto_evp 1214 */ 1215 1216 const EVP_CIPHER * 1217 EVP_aes_256_cfb8(void) 1218 { 1219 hcrypto_validate(); 1220 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, aes_256_cfb8); 1385 1221 } 1386 1222 … … 1396 1232 EVP_camellia_128_cbc(void) 1397 1233 { 1398 static const EVP_CIPHER cipher = { 1399 0, 1400 16, 1401 16, 1402 16, 1403 EVP_CIPH_CBC_MODE, 1404 camellia_init, 1405 camellia_do_cipher, 1406 camellia_cleanup, 1407 sizeof(CAMELLIA_KEY), 1408 NULL, 1409 NULL, 1410 NULL, 1411 NULL 1412 }; 1413 return &cipher; 1234 hcrypto_validate(); 1235 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_128_cbc); 1414 1236 } 1415 1237 … … 1425 1247 EVP_camellia_192_cbc(void) 1426 1248 { 1427 static const EVP_CIPHER cipher = { 1428 0, 1429 16, 1430 24, 1431 16, 1432 EVP_CIPH_CBC_MODE, 1433 camellia_init, 1434 camellia_do_cipher, 1435 camellia_cleanup, 1436 sizeof(CAMELLIA_KEY), 1437 NULL, 1438 NULL, 1439 NULL, 1440 NULL 1441 }; 1442 return &cipher; 1249 hcrypto_validate(); 1250 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_192_cbc); 1443 1251 } 1444 1252 … … 1454 1262 EVP_camellia_256_cbc(void) 1455 1263 { 1456 static const EVP_CIPHER cipher = { 1457 0, 1458 16, 1459 32, 1460 16, 1461 EVP_CIPH_CBC_MODE, 1462 camellia_init, 1463 camellia_do_cipher, 1464 camellia_cleanup, 1465 sizeof(CAMELLIA_KEY), 1466 NULL, 1467 NULL, 1468 NULL, 1469 NULL 1470 }; 1471 return &cipher; 1264 hcrypto_validate(); 1265 return EVP_DEF_OP(HCRYPTO_DEF_PROVIDER, camellia_256_cbc); 1472 1266 } 1473 1267 … … 1484 1278 { "aes-192-cbc", EVP_aes_192_cbc }, 1485 1279 { "aes-256-cbc", EVP_aes_256_cbc }, 1280 { "aes-128-cfb8", EVP_aes_128_cfb8 }, 1281 { "aes-192-cfb8", EVP_aes_192_cfb8 }, 1282 { "aes-256-cfb8", EVP_aes_256_cfb8 }, 1486 1283 { "camellia-128-cbc", EVP_camellia_128_cbc }, 1487 1284 { "camellia-192-cbc", EVP_camellia_192_cbc }, … … 1548 1345 void *ivdata) 1549 1346 { 1550 int ivlen, keylen, first = 0; 1347 unsigned int ivlen, keylen; 1348 int first = 0; 1551 1349 unsigned int mds = 0, i; 1552 1350 unsigned char *key = keydata; -
trunk/server/source4/heimdal/lib/hcrypto/evp.h
r414 r745 75 75 #define EVP_aes_192_cbc hc_EVP_aes_192_cbc 76 76 #define EVP_aes_256_cbc hc_EVP_aes_256_cbc 77 #define EVP_hcrypto_aes_128_cbc hc_EVP_hcrypto_aes_128_cbc 78 #define EVP_hcrypto_aes_192_cbc hc_EVP_hcrypto_aes_192_cbc 79 #define EVP_hcrypto_aes_256_cbc hc_EVP_hcrypto_aes_256_cbc 80 #define EVP_hcrypto_aes_128_cts hc_EVP_hcrypto_aes_128_cts 81 #define EVP_hcrypto_aes_192_cts hc_EVP_hcrypto_aes_192_cts 82 #define EVP_hcrypto_aes_256_cts hc_EVP_hcrypto_aes_256_cts 77 #define EVP_aes_128_cfb8 hc_EVP_aes_128_cfb8 78 #define EVP_aes_192_cfb8 hc_EVP_aes_192_cfb8 79 #define EVP_aes_256_cfb8 hc_EVP_aes_256_cfb8 80 83 81 #define EVP_des_cbc hc_EVP_des_cbc 84 82 #define EVP_des_ede3_cbc hc_EVP_des_ede3_cbc … … 99 97 #define EVP_sha1 hc_EVP_sha1 100 98 #define EVP_sha256 hc_EVP_sha256 99 #define EVP_sha384 hc_EVP_sha384 100 #define EVP_sha512 hc_EVP_sha512 101 101 #define PKCS5_PBKDF2_HMAC_SHA1 hc_PKCS5_PBKDF2_HMAC_SHA1 102 102 #define EVP_BytesToKey hc_EVP_BytesToKey … … 107 107 #define EVP_CIPHER_CTX_ctrl hc_EVP_CIPHER_CTX_ctrl 108 108 #define EVP_CIPHER_CTX_rand_key hc_EVP_CIPHER_CTX_rand_key 109 #define hcrypto_validate hc_hcrypto_validate 109 110 110 111 /* … … 135 136 #define EVP_CIPH_STREAM_CIPHER 0 136 137 #define EVP_CIPH_CBC_MODE 2 138 #define EVP_CIPH_CFB8_MODE 4 137 139 #define EVP_CIPH_MODE 0x7 138 140 141 #define EVP_CIPH_VARIABLE_LENGTH 0x008 /* variable key length */ 139 142 #define EVP_CIPH_ALWAYS_CALL_INIT 0x020 140 143 #define EVP_CIPH_RAND_KEY 0x200 … … 204 207 #endif 205 208 206 207 #ifdef __cplusplus 208 extern "C" { 209 #endif 209 #ifdef __cplusplus 210 #define HC_CPP_BEGIN extern "C" { 211 #define HC_CPP_END } 212 #else 213 #define HC_CPP_BEGIN 214 #define HC_CPP_END 215 #endif 216 217 HC_CPP_BEGIN 210 218 211 219 /* … … 214 222 215 223 const EVP_MD *EVP_md_null(void); 216 const EVP_MD *EVP_md2(void) HC_DEPRECATED_CRYPTO;217 const EVP_MD *EVP_md4(void) HC_DEPRECATED_CRYPTO;218 const EVP_MD *EVP_md5(void) HC_DEPRECATED_CRYPTO;224 HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md2(void); 225 HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md4(void); 226 HC_DEPRECATED_CRYPTO const EVP_MD *EVP_md5(void); 219 227 const EVP_MD *EVP_sha(void); 220 228 const EVP_MD *EVP_sha1(void); 221 229 const EVP_MD *EVP_sha256(void); 230 const EVP_MD *EVP_sha384(void); 231 const EVP_MD *EVP_sha512(void); 222 232 223 233 const EVP_CIPHER * EVP_aes_128_cbc(void); 224 234 const EVP_CIPHER * EVP_aes_192_cbc(void); 225 235 const EVP_CIPHER * EVP_aes_256_cbc(void); 226 const EVP_CIPHER * EVP_hcrypto_aes_128_cbc(void); 227 const EVP_CIPHER * EVP_hcrypto_aes_192_cbc(void); 228 const EVP_CIPHER * EVP_hcrypto_aes_256_cbc(void); 229 const EVP_CIPHER * EVP_hcrypto_aes_128_cts(void); 230 const EVP_CIPHER * EVP_hcrypto_aes_192_cts(void); 231 const EVP_CIPHER * EVP_hcrypto_aes_256_cts(void); 232 const EVP_CIPHER * EVP_des_cbc(void) HC_DEPRECATED_CRYPTO; 236 const EVP_CIPHER * EVP_aes_128_cfb8(void); 237 const EVP_CIPHER * EVP_aes_192_cfb8(void); 238 const EVP_CIPHER * EVP_aes_256_cfb8(void); 239 HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_des_cbc(void); 233 240 const EVP_CIPHER * EVP_des_ede3_cbc(void); 234 241 const EVP_CIPHER * EVP_enc_null(void); 235 const EVP_CIPHER * EVP_rc2_40_cbc(void) HC_DEPRECATED_CRYPTO;236 const EVP_CIPHER * EVP_rc2_64_cbc(void) HC_DEPRECATED_CRYPTO;237 const EVP_CIPHER * EVP_rc2_cbc(void) HC_DEPRECATED_CRYPTO;242 HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_40_cbc(void); 243 HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_64_cbc(void); 244 HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc2_cbc(void); 238 245 const EVP_CIPHER * EVP_rc4(void); 239 const EVP_CIPHER * EVP_rc4_40(void) HC_DEPRECATED_CRYPTO;246 HC_DEPRECATED_CRYPTO const EVP_CIPHER * EVP_rc4_40(void); 240 247 const EVP_CIPHER * EVP_camellia_128_cbc(void); 241 248 const EVP_CIPHER * EVP_camellia_192_cbc(void); 242 249 const EVP_CIPHER * EVP_camellia_256_cbc(void); 243 244 /*245 *246 */247 250 248 251 size_t EVP_MD_size(const EVP_MD *); … … 319 322 void OpenSSL_add_all_algorithms_noconf(void); 320 323 321 #ifdef __cplusplus 322 } 323 #endif 324 void 325 hcrypto_validate(void); 326 327 HC_CPP_END 324 328 325 329 #endif /* HEIM_EVP_H */ -
trunk/server/source4/heimdal/lib/hcrypto/hash.h
r414 r745 38 38 #define __hash_h__ 39 39 40 #include <stdlib.h>41 #include <string.h>42 #include <stddef.h>43 40 #ifdef KRB5 44 41 #include <krb5-types.h> 45 42 #endif 43 #include <roken.h> 46 44 47 45 #ifndef min … … 69 67 } 70 68 69 static inline uint64_t 70 cshift64 (uint64_t x, unsigned int n) 71 { 72 return ((uint64_t)x << (uint64_t)n) | ((uint64_t)x >> ((uint64_t)64 - (uint64_t)n)); 73 } 74 71 75 #endif /* __hash_h__ */ -
trunk/server/source4/heimdal/lib/hcrypto/hmac.c
r414 r745 53 53 } 54 54 if (ctx->opad) { 55 memset(ctx-> ipad, 0, ctx->key_length);55 memset(ctx->opad, 0, EVP_MD_block_size(ctx->md)); 56 56 free(ctx->opad); 57 57 ctx->opad = NULL; 58 58 } 59 59 if (ctx->ipad) { 60 memset(ctx->ipad, 0, ctx->key_length);60 memset(ctx->ipad, 0, EVP_MD_block_size(ctx->md)); 61 61 free(ctx->ipad); 62 62 ctx->ipad = NULL; … … 122 122 p[i] ^= ((const unsigned char *)key)[i]; 123 123 124 ctx->ctx = EVP_MD_CTX_create(); 124 if (ctx->ctx == NULL) 125 ctx->ctx = EVP_MD_CTX_create(); 125 126 126 127 EVP_DigestInit_ex(ctx->ctx, ctx->md, ctx->engine); -
trunk/server/source4/heimdal/lib/hcrypto/md4.c
r414 r745 192 192 int i; 193 193 uint32_t current[16]; 194 struct x32 *u = (struct x32*)m->save;194 struct x32 *us = (struct x32*)m->save; 195 195 for(i = 0; i < 8; i++){ 196 current[2*i+0] = swap_uint32_t(u [i].a);197 current[2*i+1] = swap_uint32_t(u [i].b);196 current[2*i+0] = swap_uint32_t(us[i].a); 197 current[2*i+1] = swap_uint32_t(us[i].b); 198 198 } 199 199 calc(m, current); -
trunk/server/source4/heimdal/lib/hcrypto/md5.c
r414 r745 216 216 int i; 217 217 uint32_t current[16]; 218 struct x32 *u = (struct x32*)m->save;218 struct x32 *us = (struct x32*)m->save; 219 219 for(i = 0; i < 8; i++){ 220 current[2*i+0] = swap_uint32_t(u [i].a);221 current[2*i+1] = swap_uint32_t(u [i].b);220 current[2*i+0] = swap_uint32_t(us[i].a); 221 current[2*i+1] = swap_uint32_t(us[i].b); 222 222 } 223 223 calc(m, current); -
trunk/server/source4/heimdal/lib/hcrypto/rand-fortuna.c
r414 r745 35 35 #include <stdlib.h> 36 36 #include <rand.h> 37 37 #include <heim_threads.h> 38 39 #ifdef KRB5 40 #include <krb5-types.h> 41 #endif 38 42 #include <roken.h> 39 43 … … 440 444 441 445 /* 446 * This mutex protects all of the above static elements from concurrent 447 * access by multiple threads 448 */ 449 static HEIMDAL_MUTEX fortuna_mutex = HEIMDAL_MUTEX_INITIALIZER; 450 451 /* 442 452 * Try our best to do an inital seed 443 453 */ 444 454 #define INIT_BYTES 128 455 456 /* 457 * fortuna_mutex must be held across calls to this function 458 */ 445 459 446 460 static int … … 452 466 abort(); 453 467 468 #ifndef NO_RAND_UNIX_METHOD 454 469 { 455 470 unsigned char buf[INIT_BYTES]; … … 460 475 } 461 476 } 477 #endif 462 478 #ifdef HAVE_ARC4RANDOM 463 479 { … … 471 487 } 472 488 #endif 489 #ifndef NO_RAND_EGD_METHOD 473 490 /* 474 491 * Only to get egd entropy if /dev/random or arc4rand failed since … … 483 500 } 484 501 } 502 #endif 485 503 /* 486 504 * Fall back to gattering data from timer and secret files, this … … 522 540 add_entropy(&main_state, (void *)&tv, sizeof(tv)); 523 541 } 542 #ifdef HAVE_GETUID 524 543 { 525 544 uid_t u = getuid(); 526 545 add_entropy(&main_state, (void *)&u, sizeof(u)); 527 546 } 547 #endif 528 548 return entropy_p; 529 549 } 530 550 551 /* 552 * fortuna_mutex must be held by callers of this function 553 */ 531 554 static int 532 555 fortuna_init(void) … … 547 570 fortuna_seed(const void *indata, int size) 548 571 { 572 HEIMDAL_MUTEX_lock(&fortuna_mutex); 573 549 574 fortuna_init(); 550 575 add_entropy(&main_state, indata, size); 551 576 if (size >= INIT_BYTES) 552 577 have_entropy = 1; 578 579 HEIMDAL_MUTEX_unlock(&fortuna_mutex); 553 580 } 554 581 … … 556 583 fortuna_bytes(unsigned char *outdata, int size) 557 584 { 585 int ret = 0; 586 587 HEIMDAL_MUTEX_lock(&fortuna_mutex); 588 558 589 if (!fortuna_init()) 559 return 0; 590 goto out; 591 560 592 resend_bytes += size; 561 593 if (resend_bytes > FORTUNA_RESEED_BYTE || resend_bytes < size) { … … 564 596 } 565 597 extract_data(&main_state, size, outdata); 566 return 1; 598 ret = 1; 599 600 out: 601 HEIMDAL_MUTEX_unlock(&fortuna_mutex); 602 603 return ret; 567 604 } 568 605 … … 570 607 fortuna_cleanup(void) 571 608 { 609 HEIMDAL_MUTEX_lock(&fortuna_mutex); 610 572 611 init_done = 0; 573 612 have_entropy = 0; 574 613 memset(&main_state, 0, sizeof(main_state)); 614 615 HEIMDAL_MUTEX_unlock(&fortuna_mutex); 575 616 } 576 617 … … 590 631 fortuna_status(void) 591 632 { 592 return fortuna_init() ? 1 : 0; 633 int result; 634 635 HEIMDAL_MUTEX_lock(&fortuna_mutex); 636 result = fortuna_init(); 637 HEIMDAL_MUTEX_unlock(&fortuna_mutex); 638 639 return result ? 1 : 0; 593 640 } 594 641 -
trunk/server/source4/heimdal/lib/hcrypto/rand-unix.c
r414 r745 43 43 #include "randi.h" 44 44 45 static int random_fd = -1;46 static HEIMDAL_MUTEX random_mutex = HEIMDAL_MUTEX_INITIALIZER;47 48 45 /* 49 46 * Unix /dev/random 50 47 */ 51 48 52 staticint53 get_device_fd(int flags)49 int 50 _hc_unix_device_fd(int flags, const char **fn) 54 51 { 55 52 static const char *rnd_devices[] = { … … 65 62 int fd = open(*p, flags | O_NDELAY); 66 63 if(fd >= 0) { 64 if (fn) 65 *fn = *p; 67 66 rk_cloexec(fd); 68 67 return fd; … … 80 79 return; 81 80 82 fd = get_device_fd(O_WRONLY);81 fd = _hc_unix_device_fd(O_WRONLY, NULL); 83 82 if (fd < 0) 84 83 return; … … 94 93 { 95 94 ssize_t count; 96 int once = 0;95 int fd; 97 96 98 if (size <= 0) 97 if (size < 0) 98 return 0; 99 else if (size == 0) 100 return 1; 101 102 fd = _hc_unix_device_fd(O_RDONLY, NULL); 103 if (fd < 0) 99 104 return 0; 100 105 101 HEIMDAL_MUTEX_lock(&random_mutex);102 if (random_fd == -1) {103 retry:104 random_fd = get_device_fd(O_RDONLY);105 if (random_fd < 0) {106 HEIMDAL_MUTEX_unlock(&random_mutex);107 return 0;108 }109 }110 111 106 while (size > 0) { 112 HEIMDAL_MUTEX_unlock(&random_mutex); 113 count = read (random_fd, outdata, size); 114 HEIMDAL_MUTEX_lock(&random_mutex); 115 if (random_fd < 0) { 116 if (errno == EINTR) 117 continue; 118 else if (errno == EBADF && once++ == 0) { 119 close(random_fd); 120 random_fd = -1; 121 goto retry; 122 } 123 return 0; 124 } else if (count <= 0) { 125 HEIMDAL_MUTEX_unlock(&random_mutex); 107 count = read(fd, outdata, size); 108 if (count < 0 && errno == EINTR) 109 continue; 110 else if (count <= 0) { 111 close(fd); 126 112 return 0; 127 113 } … … 129 115 size -= count; 130 116 } 131 HEIMDAL_MUTEX_unlock(&random_mutex);117 close(fd); 132 118 133 119 return 1; … … 156 142 int fd; 157 143 158 fd = get_device_fd(O_RDONLY);144 fd = _hc_unix_device_fd(O_RDONLY, NULL); 159 145 if (fd < 0) 160 146 return 0; -
trunk/server/source4/heimdal/lib/hcrypto/rand.c
r414 r745 3 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 4 * All rights reserved. 5 * 6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 5 7 * 6 8 * Redistribution and use in source and binary forms, with or without … … 45 47 #endif 46 48 49 #ifdef _WIN32 50 #include<shlobj.h> 51 #endif 52 47 53 /** 48 54 * @page page_rand RAND - random number … … 59 65 if (selected_meth != NULL) 60 66 return; 61 #ifdef __APPLE__ 67 #if defined(_WIN32) 68 selected_meth = &hc_rand_w32crypto_method; 69 #elif defined(__APPLE__) 62 70 selected_meth = &hc_rand_unix_method; 63 71 #else … … 96 104 RAND_bytes(void *outdata, size_t size) 97 105 { 106 if (size == 0) 107 return 1; 98 108 init_method(); 99 109 return (*selected_meth->bytes)(outdata, size); … … 342 352 if (!issuid()) { 343 353 e = getenv("RANDFILE"); 344 if (e == NULL) {354 if (e == NULL) 345 355 e = getenv("HOME"); 346 if (e) 347 pathp = 1; 348 } 349 } 356 if (e) 357 pathp = 1; 358 } 359 360 #ifndef _WIN32 350 361 /* 351 362 * Here we really want to call getpwuid(getuid()) but this will 352 363 * cause recursive lookups if the nss library uses 353 364 * gssapi/krb5/hcrypto to authenticate to the ldap servers. 365 * 366 * So at least return the unix /dev/random if we have one 354 367 */ 368 if (e == NULL) { 369 int fd; 370 371 fd = _hc_unix_device_fd(O_RDONLY, &e); 372 if (fd >= 0) 373 close(fd); 374 } 375 #else /* Win32 */ 376 377 if (e == NULL) { 378 char profile[MAX_PATH]; 379 380 if (SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 381 SHGFP_TYPE_CURRENT, profile) == S_OK) { 382 ret = snprintf(filename, size, "%s\\.rnd", profile); 383 384 if (ret > 0 && ret < size) 385 return filename; 386 } 387 } 388 389 #endif 355 390 356 391 if (e == NULL) -
trunk/server/source4/heimdal/lib/hcrypto/rand.h
r414 r745 42 42 typedef struct RAND_METHOD RAND_METHOD; 43 43 44 #include <hcrypto/bn.h>45 44 #include <hcrypto/engine.h> 46 45 … … 63 62 #define RAND_egd_method hc_RAND_egd_method 64 63 #define RAND_unix_method hc_RAND_unix_method 64 #define RAND_w32crypto_method hc_RAND_w32crypto_method 65 65 66 66 /* … … 105 105 const RAND_METHOD * RAND_unix_method(void); 106 106 const RAND_METHOD * RAND_egd_method(void); 107 const RAND_METHOD * RAND_w32crypto_method(void); 107 108 108 109 #endif /* _HEIM_RAND_H */ -
trunk/server/source4/heimdal/lib/hcrypto/randi.h
r414 r745 43 43 extern const RAND_METHOD hc_rand_egd_method; 44 44 extern const RAND_METHOD hc_rand_timer_method; 45 extern const RAND_METHOD hc_rand_w32crypto_method; 45 46 46 47 const RAND_METHOD * RAND_timer_method(void); 48 int _hc_unix_device_fd(int, const char **); 47 49 48 50 #endif /* _HEIM_RANDI_H */ -
trunk/server/source4/heimdal/lib/hcrypto/rc4.c
r414 r745 46 46 47 47 void 48 RC4_set_key(RC4_KEY *key, const int len, unsigned char *data)48 RC4_set_key(RC4_KEY *key, const int len, const unsigned char *data) 49 49 { 50 50 int i, j; -
trunk/server/source4/heimdal/lib/hcrypto/rc4.h
r414 r745 43 43 } RC4_KEY; 44 44 45 void RC4_set_key(RC4_KEY *, const int, unsigned char *);45 void RC4_set_key(RC4_KEY *, const int, const unsigned char *); 46 46 void RC4(RC4_KEY *, const int, const unsigned char *, unsigned char *); -
trunk/server/source4/heimdal/lib/hcrypto/rijndael-alg-fst.c
r414 r745 32 32 33 33 34 #include <stdlib.h> 34 35 #ifdef KRB5 35 36 #include <krb5-types.h> 36 37 #endif 37 38 38 #include <rijndael-alg-fst.h> 39 40 /* the file should not be used from outside */ 41 typedef uint8_t u8; 42 typedef uint16_t u16; 43 typedef uint32_t u32; 39 #include "rijndael-alg-fst.h" 44 40 45 41 /* … … 57 53 */ 58 54 59 static const u 32Te0[256] = {55 static const uint32_t Te0[256] = { 60 56 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, 61 57 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, … … 123 119 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, 124 120 }; 125 static const u 32Te1[256] = {121 static const uint32_t Te1[256] = { 126 122 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, 127 123 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, … … 189 185 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, 190 186 }; 191 static const u 32Te2[256] = {187 static const uint32_t Te2[256] = { 192 188 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, 193 189 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, … … 255 251 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, 256 252 }; 257 static const u 32Te3[256] = {253 static const uint32_t Te3[256] = { 258 254 259 255 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, … … 322 318 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, 323 319 }; 324 static const u 32Te4[256] = {320 static const uint32_t Te4[256] = { 325 321 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, 326 322 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, … … 388 384 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, 389 385 }; 390 static const u 32Td0[256] = {386 static const uint32_t Td0[256] = { 391 387 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 392 388 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, … … 454 450 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, 455 451 }; 456 static const u 32Td1[256] = {452 static const uint32_t Td1[256] = { 457 453 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, 458 454 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, … … 520 516 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, 521 517 }; 522 static const u 32Td2[256] = {518 static const uint32_t Td2[256] = { 523 519 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, 524 520 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, … … 587 583 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, 588 584 }; 589 static const u 32Td3[256] = {585 static const uint32_t Td3[256] = { 590 586 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, 591 587 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, … … 653 649 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, 654 650 }; 655 static const u 32Td4[256] = {651 static const uint32_t Td4[256] = { 656 652 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, 657 653 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, … … 719 715 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, 720 716 }; 721 static const u 32rcon[] = {717 static const uint32_t rcon[] = { 722 718 0x01000000, 0x02000000, 0x04000000, 0x08000000, 723 719 0x10000000, 0x20000000, 0x40000000, 0x80000000, … … 728 724 729 725 #ifdef _MSC_VER 730 #define GETU32(p) SWAP(*((u 32*)(p)))731 #define PUTU32(ct, st) { *((u 32*)(ct)) = SWAP((st)); }726 #define GETU32(p) SWAP(*((uint32_t *)(p))) 727 #define PUTU32(ct, st) { *((uint32_t *)(ct)) = SWAP((st)); } 732 728 #else 733 #define GETU32(pt) (((u 32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ ((u32)(pt)[3]))734 #define PUTU32(ct, st) { (ct)[0] = (u 8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }729 #define GETU32(pt) (((uint32_t)(pt)[0] << 24) ^ ((uint32_t)(pt)[1] << 16) ^ ((uint32_t)(pt)[2] << 8) ^ ((uint32_t)(pt)[3])) 730 #define PUTU32(ct, st) { (ct)[0] = (uint8_t)((st) >> 24); (ct)[1] = (uint8_t)((st) >> 16); (ct)[2] = (uint8_t)((st) >> 8); (ct)[3] = (uint8_t)(st); } 735 731 #endif 736 732 … … 740 736 * @return the number of rounds for the given cipher key size. 741 737 */ 742 int rijndaelKeySetupEnc(u 32 rk[/*4*(Nr + 1)*/], const u8cipherKey[], int keyBits) {738 int rijndaelKeySetupEnc(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) { 743 739 int i = 0; 744 u 32temp;740 uint32_t temp; 745 741 746 742 rk[0] = GETU32(cipherKey ); … … 826 822 * @return the number of rounds for the given cipher key size. 827 823 */ 828 int rijndaelKeySetupDec(u 32 rk[/*4*(Nr + 1)*/], const u8cipherKey[], int keyBits) {824 int rijndaelKeySetupDec(uint32_t rk[/*4*(Nr + 1)*/], const uint8_t cipherKey[], int keyBits) { 829 825 int Nr, i, j; 830 u 32temp;826 uint32_t temp; 831 827 832 828 /* expand the cipher key: */ … … 866 862 } 867 863 868 void rijndaelEncrypt(const u 32 rk[/*4*(Nr + 1)*/], int Nr, const u8 pt[16], u8ct[16]) {869 u 32s0, s1, s2, s3, t0, t1, t2, t3;864 void rijndaelEncrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t pt[16], uint8_t ct[16]) { 865 uint32_t s0, s1, s2, s3, t0, t1, t2, t3; 870 866 #ifndef FULL_UNROLL 871 867 int r; … … 1047 1043 } 1048 1044 1049 void rijndaelDecrypt(const u 32 rk[/*4*(Nr + 1)*/], int Nr, const u8 ct[16], u8pt[16]) {1050 u 32s0, s1, s2, s3, t0, t1, t2, t3;1045 void rijndaelDecrypt(const uint32_t rk[/*4*(Nr + 1)*/], int Nr, const uint8_t ct[16], uint8_t pt[16]) { 1046 uint32_t s0, s1, s2, s3, t0, t1, t2, t3; 1051 1047 #ifndef FULL_UNROLL 1052 1048 int r; -
trunk/server/source4/heimdal/lib/hcrypto/rnd_keys.c
r414 r745 40 40 #include <krb5-types.h> 41 41 #endif 42 #include <stdlib.h> 43 42 44 #include <des.h> 43 45 #include <rand.h> 44 45 #include <stdlib.h>46 46 47 47 #undef __attribute__ -
trunk/server/source4/heimdal/lib/hcrypto/rsa.c
r414 r745 39 39 #include <rfc2459_asn1.h> 40 40 41 #include <der.h> 42 41 43 #include <rsa.h> 44 45 #include "common.h" 42 46 43 47 #include <roken.h> … … 48 52 * RSA is named by its inventors (Ron Rivest, Adi Shamir, and Leonard 49 53 * Adleman) (published in 1977), patented expired in 21 September 2000. 54 * 55 * 56 * Speed for RSA in seconds 57 * no key blinding 58 * 1000 iteration, 59 * same rsa keys (1024 and 2048) 60 * operation performed each eteration sign, verify, encrypt, decrypt on a random bit pattern 61 * 62 * name 1024 2048 4098 63 * ================================= 64 * gmp: 0.73 6.60 44.80 65 * tfm: 2.45 -- -- 66 * ltm: 3.79 20.74 105.41 (default in hcrypto) 67 * openssl: 4.04 11.90 82.59 68 * cdsa: 15.89 102.89 721.40 69 * imath: 40.62 -- -- 50 70 * 51 71 * See the library functions here: @ref hcrypto_rsa … … 238 258 239 259 void * 240 RSA_get_app_data( RSA *rsa)260 RSA_get_app_data(const RSA *rsa) 241 261 { 242 262 return rsa->ex_data.sk; … … 279 299 } 280 300 281 if (ret == sizeof(inbuf) && memcmp(buffer, inbuf, sizeof(inbuf)) == 0) {301 if (ret == sizeof(inbuf) && ct_memcmp(buffer, inbuf, sizeof(inbuf)) == 0) { 282 302 free(buffer); 283 303 return 1; … … 304 324 RSAFUNC(RSA_private_decrypt, (r)->meth->rsa_priv_dec(flen, f, t, r, p)) 305 325 306 /* XXX */ 326 static const heim_octet_string null_entry_oid = { 2, rk_UNCONST("\x05\x00") }; 327 328 static const unsigned sha1_oid_tree[] = { 1, 3, 14, 3, 2, 26 }; 329 static const AlgorithmIdentifier _signature_sha1_data = { 330 { 6, rk_UNCONST(sha1_oid_tree) }, rk_UNCONST(&null_entry_oid) 331 }; 332 static const unsigned sha256_oid_tree[] = { 2, 16, 840, 1, 101, 3, 4, 2, 1 }; 333 static const AlgorithmIdentifier _signature_sha256_data = { 334 { 9, rk_UNCONST(sha256_oid_tree) }, rk_UNCONST(&null_entry_oid) 335 }; 336 static const unsigned md5_oid_tree[] = { 1, 2, 840, 113549, 2, 5 }; 337 static const AlgorithmIdentifier _signature_md5_data = { 338 { 6, rk_UNCONST(md5_oid_tree) }, rk_UNCONST(&null_entry_oid) 339 }; 340 341 307 342 int 308 343 RSA_sign(int type, const unsigned char *from, unsigned int flen, 309 344 unsigned char *to, unsigned int *tlen, RSA *rsa) 310 345 { 311 return -1; 346 if (rsa->meth->rsa_sign) 347 return rsa->meth->rsa_sign(type, from, flen, to, tlen, rsa); 348 349 if (rsa->meth->rsa_priv_enc) { 350 heim_octet_string indata; 351 DigestInfo di; 352 size_t size; 353 int ret; 354 355 memset(&di, 0, sizeof(di)); 356 357 if (type == NID_sha1) { 358 di.digestAlgorithm = _signature_sha1_data; 359 } else if (type == NID_md5) { 360 di.digestAlgorithm = _signature_md5_data; 361 } else if (type == NID_sha256) { 362 di.digestAlgorithm = _signature_sha256_data; 363 } else 364 return -1; 365 366 di.digest.data = rk_UNCONST(from); 367 di.digest.length = flen; 368 369 ASN1_MALLOC_ENCODE(DigestInfo, 370 indata.data, 371 indata.length, 372 &di, 373 &size, 374 ret); 375 if (ret) 376 return ret; 377 if (indata.length != size) 378 abort(); 379 380 ret = rsa->meth->rsa_priv_enc(indata.length, indata.data, to, 381 rsa, RSA_PKCS1_PADDING); 382 free(indata.data); 383 if (ret > 0) { 384 *tlen = ret; 385 ret = 1; 386 } else 387 ret = 0; 388 389 return ret; 390 } 391 392 return 0; 312 393 } 313 394 314 395 int 315 396 RSA_verify(int type, const unsigned char *from, unsigned int flen, 316 unsigned char *to, unsigned int tlen, RSA *rsa) 317 { 318 return -1; 397 unsigned char *sigbuf, unsigned int siglen, RSA *rsa) 398 { 399 if (rsa->meth->rsa_verify) 400 return rsa->meth->rsa_verify(type, from, flen, sigbuf, siglen, rsa); 401 402 if (rsa->meth->rsa_pub_dec) { 403 const AlgorithmIdentifier *digest_alg; 404 void *data; 405 DigestInfo di; 406 size_t size; 407 int ret, ret2; 408 409 data = malloc(RSA_size(rsa)); 410 if (data == NULL) 411 return -1; 412 413 memset(&di, 0, sizeof(di)); 414 415 ret = rsa->meth->rsa_pub_dec(siglen, sigbuf, data, rsa, RSA_PKCS1_PADDING); 416 if (ret <= 0) { 417 free(data); 418 return -2; 419 } 420 421 ret2 = decode_DigestInfo(data, ret, &di, &size); 422 free(data); 423 if (ret2 != 0) 424 return -3; 425 if (ret != size) { 426 free_DigestInfo(&di); 427 return -4; 428 } 429 430 if (flen != di.digest.length || memcmp(di.digest.data, from, flen) != 0) { 431 free_DigestInfo(&di); 432 return -5; 433 } 434 435 if (type == NID_sha1) { 436 digest_alg = &_signature_sha1_data; 437 } else if (type == NID_md5) { 438 digest_alg = &_signature_md5_data; 439 } else if (type == NID_sha256) { 440 digest_alg = &_signature_sha256_data; 441 } else { 442 free_DigestInfo(&di); 443 return -1; 444 } 445 446 ret = der_heim_oid_cmp(&digest_alg->algorithm, 447 &di.digestAlgorithm.algorithm); 448 free_DigestInfo(&di); 449 450 if (ret != 0) 451 return 0; 452 return 1; 453 } 454 455 return 0; 319 456 } 320 457 … … 381 518 } 382 519 383 extern const RSA_METHOD hc_rsa_imath_method; 384 #ifdef HAVE_GMP 385 static const RSA_METHOD *default_rsa_method = &hc_rsa_gmp_method; 386 #else 387 static const RSA_METHOD *default_rsa_method = &hc_rsa_imath_method; 388 #endif 520 extern const RSA_METHOD hc_rsa_gmp_method; 521 extern const RSA_METHOD hc_rsa_tfm_method; 522 extern const RSA_METHOD hc_rsa_ltm_method; 523 static const RSA_METHOD *default_rsa_method = &hc_rsa_ltm_method; 524 389 525 390 526 const RSA_METHOD * … … 403 539 * 404 540 */ 405 406 static BIGNUM *407 heim_int2BN(const heim_integer *i)408 {409 BIGNUM *bn;410 411 bn = BN_bin2bn(i->data, i->length, NULL);412 if (bn)413 BN_set_negative(bn, i->negative);414 return bn;415 }416 417 static int418 bn2heim_int(BIGNUM *bn, heim_integer *integer)419 {420 integer->length = BN_num_bytes(bn);421 integer->data = malloc(integer->length);422 if (integer->data == NULL) {423 integer->length = 0;424 return ENOMEM;425 }426 BN_bn2bin(bn, integer->data);427 integer->negative = BN_is_negative(bn);428 return 0;429 }430 431 541 432 542 RSA * … … 452 562 } 453 563 454 k->n = heim_int2BN(&data.modulus);455 k->e = heim_int2BN(&data.publicExponent);456 k->d = heim_int2BN(&data.privateExponent);457 k->p = heim_int2BN(&data.prime1);458 k->q = heim_int2BN(&data.prime2);459 k->dmp1 = heim_int2BN(&data.exponent1);460 k->dmq1 = heim_int2BN(&data.exponent2);461 k->iqmp = heim_int2BN(&data.coefficient);564 k->n = _hc_integer_to_BN(&data.modulus, NULL); 565 k->e = _hc_integer_to_BN(&data.publicExponent, NULL); 566 k->d = _hc_integer_to_BN(&data.privateExponent, NULL); 567 k->p = _hc_integer_to_BN(&data.prime1, NULL); 568 k->q = _hc_integer_to_BN(&data.prime2, NULL); 569 k->dmp1 = _hc_integer_to_BN(&data.exponent1, NULL); 570 k->dmq1 = _hc_integer_to_BN(&data.exponent2, NULL); 571 k->iqmp = _hc_integer_to_BN(&data.coefficient, NULL); 462 572 free_RSAPrivateKey(&data); 463 573 … … 486 596 memset(&data, 0, sizeof(data)); 487 597 488 ret = bn2heim_int(rsa->n, &data.modulus);489 ret |= bn2heim_int(rsa->e, &data.publicExponent);490 ret |= bn2heim_int(rsa->d, &data.privateExponent);491 ret |= bn2heim_int(rsa->p, &data.prime1);492 ret |= bn2heim_int(rsa->q, &data.prime2);493 ret |= bn2heim_int(rsa->dmp1, &data.exponent1);494 ret |= bn2heim_int(rsa->dmq1, &data.exponent2);495 ret |= bn2heim_int(rsa->iqmp, &data.coefficient);598 ret = _hc_BN_to_integer(rsa->n, &data.modulus); 599 ret |= _hc_BN_to_integer(rsa->e, &data.publicExponent); 600 ret |= _hc_BN_to_integer(rsa->d, &data.privateExponent); 601 ret |= _hc_BN_to_integer(rsa->p, &data.prime1); 602 ret |= _hc_BN_to_integer(rsa->q, &data.prime2); 603 ret |= _hc_BN_to_integer(rsa->dmp1, &data.exponent1); 604 ret |= _hc_BN_to_integer(rsa->dmq1, &data.exponent2); 605 ret |= _hc_BN_to_integer(rsa->iqmp, &data.coefficient); 496 606 if (ret) { 497 607 free_RSAPrivateKey(&data); … … 531 641 memset(&data, 0, sizeof(data)); 532 642 533 if ( bn2heim_int(rsa->n, &data.modulus) ||534 bn2heim_int(rsa->e, &data.publicExponent))643 if (_hc_BN_to_integer(rsa->n, &data.modulus) || 644 _hc_BN_to_integer(rsa->e, &data.publicExponent)) 535 645 { 536 646 free_RSAPublicKey(&data); … … 560 670 return size; 561 671 } 672 673 RSA * 674 d2i_RSAPublicKey(RSA *rsa, const unsigned char **pp, size_t len) 675 { 676 RSAPublicKey data; 677 RSA *k = rsa; 678 size_t size; 679 int ret; 680 681 ret = decode_RSAPublicKey(*pp, len, &data, &size); 682 if (ret) 683 return NULL; 684 685 *pp += size; 686 687 if (k == NULL) { 688 k = RSA_new(); 689 if (k == NULL) { 690 free_RSAPublicKey(&data); 691 return NULL; 692 } 693 } 694 695 k->n = _hc_integer_to_BN(&data.modulus, NULL); 696 k->e = _hc_integer_to_BN(&data.publicExponent, NULL); 697 698 free_RSAPublicKey(&data); 699 700 if (k->n == NULL || k->e == NULL) { 701 RSA_free(k); 702 return NULL; 703 } 704 705 return k; 706 } -
trunk/server/source4/heimdal/lib/hcrypto/rsa.h
r414 r745 41 41 /* symbol renaming */ 42 42 #define RSA_null_method hc_RSA_null_method 43 #define RSA_ imath_method hc_RSA_imath_method43 #define RSA_ltm_method hc_RSA_ltm_method 44 44 #define RSA_gmp_method hc_RSA_gmp_method 45 #define RSA_tfm_method hc_RSA_tfm_method 45 46 #define RSA_new hc_RSA_new 46 47 #define RSA_new_method hc_RSA_new_method … … 65 66 #define i2d_RSAPrivateKey hc_i2d_RSAPrivateKey 66 67 #define i2d_RSAPublicKey hc_i2d_RSAPublicKey 68 #define d2i_RSAPublicKey hc_d2i_RSAPublicKey 67 69 68 70 /* … … 134 136 135 137 const RSA_METHOD *RSA_null_method(void); 136 const RSA_METHOD *RSA_imath_method(void);137 138 const RSA_METHOD *RSA_gmp_method(void); 139 const RSA_METHOD *RSA_tfm_method(void); 140 const RSA_METHOD *RSA_ltm_method(void); 138 141 139 142 /* … … 153 156 154 157 int RSA_set_app_data(RSA *, void *arg); 155 void * RSA_get_app_data( RSA *);158 void * RSA_get_app_data(const RSA *); 156 159 157 160 int RSA_check_key(const RSA *); … … 174 177 175 178 int i2d_RSAPublicKey(RSA *, unsigned char **); 179 RSA * d2i_RSAPublicKey(RSA *, const unsigned char **, size_t); 176 180 177 181 #endif /* _HEIM_RSA_H */ -
trunk/server/source4/heimdal/lib/hcrypto/sha.c
r414 r745 241 241 #if !defined(WORDS_BIGENDIAN) || defined(_CRAY) 242 242 int i; 243 uint32_t current[16];244 struct x32 *u = (struct x32*)m->save;243 uint32_t SHA1current[16]; 244 struct x32 *us = (struct x32*)m->save; 245 245 for(i = 0; i < 8; i++){ 246 current[2*i+0] = swap_uint32_t(u[i].a);247 current[2*i+1] = swap_uint32_t(u[i].b);246 SHA1current[2*i+0] = swap_uint32_t(us[i].a); 247 SHA1current[2*i+1] = swap_uint32_t(us[i].b); 248 248 } 249 calc(m, current);249 calc(m, SHA1current); 250 250 #else 251 251 calc(m, (uint32_t*)m->save); -
trunk/server/source4/heimdal/lib/hcrypto/sha.h
r414 r745 44 44 #define SHA256_Update hc_SHA256_Update 45 45 #define SHA256_Final hc_SHA256_Final 46 #define SHA384_Init hc_SHA384_Init 47 #define SHA384_Update hc_SHA384_Update 48 #define SHA384_Final hc_SHA384_Final 49 #define SHA512_Init hc_SHA512_Init 50 #define SHA512_Update hc_SHA512_Update 51 #define SHA512_Final hc_SHA512_Final 46 52 47 53 /* … … 81 87 void SHA256_Final (void *, SHA256_CTX *); 82 88 89 /* 90 * SHA-2 512 91 */ 92 93 #define SHA512_DIGEST_LENGTH 64 94 95 struct hc_sha512state { 96 uint64_t sz[2]; 97 uint64_t counter[8]; 98 unsigned char save[128]; 99 }; 100 101 typedef struct hc_sha512state SHA512_CTX; 102 103 void SHA512_Init (SHA512_CTX *); 104 void SHA512_Update (SHA512_CTX *, const void *, size_t); 105 void SHA512_Final (void *, SHA512_CTX *); 106 107 #define SHA384_DIGEST_LENGTH 48 108 109 typedef struct hc_sha512state SHA384_CTX; 110 111 void SHA384_Init (SHA384_CTX *); 112 void SHA384_Update (SHA384_CTX *, const void *, size_t); 113 void SHA384_Final (void *, SHA384_CTX *); 114 83 115 #endif /* HEIM_SHA_H */ -
trunk/server/source4/heimdal/lib/hcrypto/sha256.c
r414 r745 184 184 int i; 185 185 uint32_t current[16]; 186 struct x32 *u = (struct x32*)m->save;186 struct x32 *us = (struct x32*)m->save; 187 187 for(i = 0; i < 8; i++){ 188 current[2*i+0] = swap_uint32_t(u [i].a);189 current[2*i+1] = swap_uint32_t(u [i].b);188 current[2*i+0] = swap_uint32_t(us[i].a); 189 current[2*i+1] = swap_uint32_t(us[i].b); 190 190 } 191 191 calc(m, current); -
trunk/server/source4/heimdal/lib/hcrypto/ui.c
r414 r745 38 38 #include <string.h> 39 39 #include <signal.h> 40 #ifdef HAVE_TERMIOS_H 40 41 #include <termios.h> 42 #endif 41 43 #include <roken.h> 42 44 43 45 #include <ui.h> 46 #ifdef HAVE_CONIO_H 47 #include <conio.h> 48 #endif 44 49 45 50 static sig_atomic_t intr_flag; … … 50 55 intr_flag++; 51 56 } 57 58 #ifdef HAVE_CONIO_H 59 60 /* 61 * Windows does console slightly different then then unix case. 62 */ 63 64 static int 65 read_string(const char *preprompt, const char *prompt, 66 char *buf, size_t len, int echo) 67 { 68 int of = 0; 69 int c; 70 char *p; 71 void (*oldsigintr)(int); 72 73 _cprintf("%s%s", preprompt, prompt); 74 75 oldsigintr = signal(SIGINT, intr); 76 77 p = buf; 78 while(intr_flag == 0){ 79 c = ((echo)? _getche(): _getch()); 80 if(c == '\n' || c == '\r') 81 break; 82 if(of == 0) 83 *p++ = c; 84 of = (p == buf + len); 85 } 86 if(of) 87 p--; 88 *p = 0; 89 90 if(echo == 0){ 91 printf("\n"); 92 } 93 94 signal(SIGINT, oldsigintr); 95 96 if(intr_flag) 97 return -2; 98 if(of) 99 return -1; 100 return 0; 101 } 102 103 #else /* !HAVE_CONIO_H */ 52 104 53 105 #ifndef NSIG … … 136 188 } 137 189 190 #endif /* HAVE_CONIO_H */ 191 138 192 int 139 193 UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
Note:
See TracChangeset
for help on using the changeset viewer.