Deleted Added
full compact
bad_dtls_test.c (312826) bad_dtls_test.c (326663)
1/*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */

--- 576 unchanged lines hidden (view full) ---

585 unsigned char lenbytes[2];
586 HMAC_CTX ctx;
587 EVP_CIPHER_CTX enc_ctx;
588 unsigned char iv[16];
589 unsigned char pad;
590 unsigned char *enc;
591
592#ifdef SIXTY_FOUR_BIT_LONG
1/*
2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */

--- 576 unchanged lines hidden (view full) ---

585 unsigned char lenbytes[2];
586 HMAC_CTX ctx;
587 EVP_CIPHER_CTX enc_ctx;
588 unsigned char iv[16];
589 unsigned char pad;
590 unsigned char *enc;
591
592#ifdef SIXTY_FOUR_BIT_LONG
593 seq[0] = (seqnr >> 40) & 0xff;
594 seq[1] = (seqnr >> 32) & 0xff;
593 seq[0] = (unsigned char)(seqnr >> 40);
594 seq[1] = (unsigned char)(seqnr >> 32);
595#endif
595#endif
596 seq[2] = (seqnr >> 24) & 0xff;
597 seq[3] = (seqnr >> 16) & 0xff;
598 seq[4] = (seqnr >> 8) & 0xff;
599 seq[5] = seqnr & 0xff;
596 seq[2] = (unsigned char)(seqnr >> 24);
597 seq[3] = (unsigned char)(seqnr >> 16);
598 seq[4] = (unsigned char)(seqnr >> 8);
599 seq[5] = (unsigned char)(seqnr);
600
601 pad = 15 - ((len + SHA_DIGEST_LENGTH) % 16);
602 enc = OPENSSL_malloc(len + SHA_DIGEST_LENGTH + 1 + pad);
603 if (enc == NULL)
604 return 0;
605
606 /* Copy record to encryption buffer */
607 memcpy(enc, msg, len);
608
609 /* Append HMAC to data */
610 HMAC_Init(&ctx, mac_key, 20, EVP_sha1());
611 HMAC_Update(&ctx, epoch, 2);
612 HMAC_Update(&ctx, seq, 6);
613 HMAC_Update(&ctx, &type, 1);
614 HMAC_Update(&ctx, ver, 2); /* Version */
600
601 pad = 15 - ((len + SHA_DIGEST_LENGTH) % 16);
602 enc = OPENSSL_malloc(len + SHA_DIGEST_LENGTH + 1 + pad);
603 if (enc == NULL)
604 return 0;
605
606 /* Copy record to encryption buffer */
607 memcpy(enc, msg, len);
608
609 /* Append HMAC to data */
610 HMAC_Init(&ctx, mac_key, 20, EVP_sha1());
611 HMAC_Update(&ctx, epoch, 2);
612 HMAC_Update(&ctx, seq, 6);
613 HMAC_Update(&ctx, &type, 1);
614 HMAC_Update(&ctx, ver, 2); /* Version */
615 lenbytes[0] = len >> 8;
616 lenbytes[1] = len & 0xff;
615 lenbytes[0] = (unsigned char)(len >> 8);
616 lenbytes[1] = (unsigned char)(len);
617 HMAC_Update(&ctx, lenbytes, 2); /* Length */
618 HMAC_Update(&ctx, enc, len); /* Finally the data itself */
619 HMAC_Final(&ctx, enc + len, NULL);
620 HMAC_CTX_cleanup(&ctx);
621
622 /* Append padding bytes */
623 len += SHA_DIGEST_LENGTH;
624 do {

--- 7 unchanged lines hidden (view full) ---

632 EVP_Cipher(&enc_ctx, enc, enc, len);
633 EVP_CIPHER_CTX_cleanup(&enc_ctx);
634
635 /* Finally write header (from fragmented variables), IV and encrypted record */
636 BIO_write(rbio, &type, 1);
637 BIO_write(rbio, ver, 2);
638 BIO_write(rbio, epoch, 2);
639 BIO_write(rbio, seq, 6);
617 HMAC_Update(&ctx, lenbytes, 2); /* Length */
618 HMAC_Update(&ctx, enc, len); /* Finally the data itself */
619 HMAC_Final(&ctx, enc + len, NULL);
620 HMAC_CTX_cleanup(&ctx);
621
622 /* Append padding bytes */
623 len += SHA_DIGEST_LENGTH;
624 do {

--- 7 unchanged lines hidden (view full) ---

632 EVP_Cipher(&enc_ctx, enc, enc, len);
633 EVP_CIPHER_CTX_cleanup(&enc_ctx);
634
635 /* Finally write header (from fragmented variables), IV and encrypted record */
636 BIO_write(rbio, &type, 1);
637 BIO_write(rbio, ver, 2);
638 BIO_write(rbio, epoch, 2);
639 BIO_write(rbio, seq, 6);
640 lenbytes[0] = (len + sizeof(iv)) >> 8;
641 lenbytes[1] = (len + sizeof(iv)) & 0xff;
640 lenbytes[0] = (unsigned char)((len + sizeof(iv)) >> 8);
641 lenbytes[1] = (unsigned char)(len + sizeof(iv));
642 BIO_write(rbio, lenbytes, 2);
643
644 BIO_write(rbio, iv, sizeof(iv));
645 BIO_write(rbio, enc, len);
646
647 OPENSSL_free(enc);
648 return 1;
649}

--- 277 unchanged lines hidden ---
642 BIO_write(rbio, lenbytes, 2);
643
644 BIO_write(rbio, iv, sizeof(iv));
645 BIO_write(rbio, enc, len);
646
647 OPENSSL_free(enc);
648 return 1;
649}

--- 277 unchanged lines hidden ---