libidav/crypto.c

changeset 462
efda9aa1bbad
parent 459
2c112cbaa08e
child 470
6bf798ad3aec
child 481
ff477f1f7765
equal deleted inserted replaced
460:22522ff52a62 462:efda9aa1bbad
527 527
528 unsigned char *out = NULL; 528 unsigned char *out = NULL;
529 size_t outlen = 0; 529 size_t outlen = 0;
530 size_t ivl = enc->ivlen; 530 size_t ivl = enc->ivlen;
531 if(in_len != 0) { 531 if(in_len != 0) {
532 outlen = len + 16; 532 outlen = len + 32;
533 out = malloc(outlen + ivl); 533 out = malloc(outlen + ivl);
534 if(enc->iv) { 534 if(enc->iv) {
535 memcpy(out, enc->iv, ivl); 535 memcpy(out, enc->iv, ivl);
536 } 536 }
537 537
538 CCCryptorStatus status; 538 CCCryptorStatus status;
539 size_t avail = outlen; 539 size_t avail = outlen;
540 status = CCCryptorUpdate(enc->ctx, in, in_len, out + ivl, avail, &outlen); 540 status = CCCryptorUpdate(enc->ctx, in, in_len, out + ivl, avail, &outlen);
541 541 if(in_len != len) {
542 free(in); 542 int newoutlen = 16;
543 status = CCCryptorFinal(enc->ctx, out + ivl + outlen, 16, &newoutlen);
544 outlen += newoutlen;
545 enc->end = 1;
546 }
543 } else { 547 } else {
544 out = malloc(32); 548 out = malloc(32);
545 CCCryptorStatus status; 549 CCCryptorStatus status;
546 size_t avail = outlen; 550 size_t avail = outlen;
547 status = CCCryptorFinal(enc->ctx, out, 32, &outlen); 551 status = CCCryptorFinal(enc->ctx, out, 32, &outlen);
548 enc->end = 1; 552 enc->end = 1;
549 free(in);
550 } 553 }
551 enc->tmp = (char*)out; 554 enc->tmp = (char*)out;
552 enc->tmplen = outlen + ivl; 555 enc->tmplen = outlen + ivl;
553 enc->tmpoff = 0; 556 enc->tmpoff = 0;
554 557
555 if(enc->iv) { 558 if(enc->iv) {
556 free(enc->iv); 559 free(enc->iv);
557 enc->iv = NULL; 560 enc->iv = NULL;
558 enc->ivlen = 0; 561 enc->ivlen = 0;
559 } 562 }
563
564 free(in);
560 565
561 return aes_read(buf, s, n, enc); 566 return aes_read(buf, s, n, enc);
562 } 567 }
563 568
564 void aes_encrypter_close(AESEncrypter *enc) { 569 void aes_encrypter_close(AESEncrypter *enc) {

mercurial