tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

cipher_test_cases.c (15722B)


      1 /*
      2 *
      3 * Copyright (c) 2013-2021, Cisco Systems, Inc.
      4 * All rights reserved.
      5 *
      6 * Redistribution and use in source and binary forms, with or without
      7 * modification, are permitted provided that the following conditions
      8 * are met:
      9 *
     10 *   Redistributions of source code must retain the above copyright
     11 *   notice, this list of conditions and the following disclaimer.
     12 *
     13 *   Redistributions in binary form must reproduce the above
     14 *   copyright notice, this list of conditions and the following
     15 *   disclaimer in the documentation and/or other materials provided
     16 *   with the distribution.
     17 *
     18 *   Neither the name of the Cisco Systems, Inc. nor the names of its
     19 *   contributors may be used to endorse or promote products derived
     20 *   from this software without specific prior written permission.
     21 *
     22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     33 * OF THE POSSIBILITY OF SUCH DAMAGE.
     34 *
     35 */
     36 
     37 #include "cipher_test_cases.h"
     38 #include <stddef.h>
     39 
     40 /*
     41 * KAT values for AES self-test.  These
     42 * values came from the legacy libsrtp code.
     43 */
     44 /* clang-format off */
     45 static const uint8_t srtp_aes_icm_128_test_case_0_key[SRTP_AES_ICM_128_KEY_LEN_WSALT] = {
     46    0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
     47    0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
     48    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
     49    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
     50 };
     51 /* clang-format on */
     52 
     53 /* clang-format off */
     54 static uint8_t srtp_aes_icm_128_test_case_0_nonce[16] = {
     55    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     56    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
     57 };
     58 /* clang-format on */
     59 
     60 /* clang-format off */
     61 static const uint8_t srtp_aes_icm_128_test_case_0_plaintext[32] =  {
     62    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     63    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     64    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     65    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     66 };
     67 /* clang-format on */
     68 
     69 /* clang-format off */
     70 static const uint8_t srtp_aes_icm_128_test_case_0_ciphertext[32] = {
     71    0xe0, 0x3e, 0xad, 0x09, 0x35, 0xc9, 0x5e, 0x80,
     72    0xe1, 0x66, 0xb1, 0x6d, 0xd9, 0x2b, 0x4e, 0xb4,
     73    0xd2, 0x35, 0x13, 0x16, 0x2b, 0x02, 0xd0, 0xf7,
     74    0x2a, 0x43, 0xa2, 0xfe, 0x4a, 0x5f, 0x97, 0xab
     75 };
     76 /* clang-format on */
     77 
     78 const srtp_cipher_test_case_t srtp_aes_icm_128_test_case_0 = {
     79    SRTP_AES_ICM_128_KEY_LEN_WSALT,          /* octets in key            */
     80    srtp_aes_icm_128_test_case_0_key,        /* key                      */
     81    srtp_aes_icm_128_test_case_0_nonce,      /* packet index             */
     82    32,                                      /* octets in plaintext      */
     83    srtp_aes_icm_128_test_case_0_plaintext,  /* plaintext                */
     84    32,                                      /* octets in ciphertext     */
     85    srtp_aes_icm_128_test_case_0_ciphertext, /* ciphertext               */
     86    0,                                       /* */
     87    NULL,                                    /* */
     88    0,                                       /* */
     89    NULL                                     /* pointer to next testcase */
     90 };
     91 
     92 /*
     93 * KAT values for AES-192-CTR self-test.  These
     94 * values came from section 7 of RFC 6188.
     95 */
     96 /* clang-format off */
     97 static const uint8_t srtp_aes_icm_192_test_case_0_key[SRTP_AES_ICM_192_KEY_LEN_WSALT] = {
     98    0xea, 0xb2, 0x34, 0x76, 0x4e, 0x51, 0x7b, 0x2d,
     99    0x3d, 0x16, 0x0d, 0x58, 0x7d, 0x8c, 0x86, 0x21,
    100    0x97, 0x40, 0xf6, 0x5f, 0x99, 0xb6, 0xbc, 0xf7,
    101    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
    102    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
    103 };
    104 /* clang-format on */
    105 
    106 /* clang-format off */
    107 static uint8_t srtp_aes_icm_192_test_case_0_nonce[16] = {
    108    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    109    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    110 };
    111 /* clang-format on */
    112 
    113 /* clang-format off */
    114 static const uint8_t srtp_aes_icm_192_test_case_0_plaintext[32] =  {
    115    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    116    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    117    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    118    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    119 };
    120 /* clang-format on */
    121 
    122 /* clang-format off */
    123 static const uint8_t srtp_aes_icm_192_test_case_0_ciphertext[32] = {
    124    0x35, 0x09, 0x6c, 0xba, 0x46, 0x10, 0x02, 0x8d,
    125    0xc1, 0xb5, 0x75, 0x03, 0x80, 0x4c, 0xe3, 0x7c,
    126    0x5d, 0xe9, 0x86, 0x29, 0x1d, 0xcc, 0xe1, 0x61,
    127    0xd5, 0x16, 0x5e, 0xc4, 0x56, 0x8f, 0x5c, 0x9a
    128 };
    129 /* clang-format on */
    130 
    131 const srtp_cipher_test_case_t srtp_aes_icm_192_test_case_0 = {
    132    SRTP_AES_ICM_192_KEY_LEN_WSALT,          /* octets in key            */
    133    srtp_aes_icm_192_test_case_0_key,        /* key                      */
    134    srtp_aes_icm_192_test_case_0_nonce,      /* packet index             */
    135    32,                                      /* octets in plaintext      */
    136    srtp_aes_icm_192_test_case_0_plaintext,  /* plaintext                */
    137    32,                                      /* octets in ciphertext     */
    138    srtp_aes_icm_192_test_case_0_ciphertext, /* ciphertext               */
    139    0,                                       /* */
    140    NULL,                                    /* */
    141    0,                                       /* */
    142    NULL                                     /* pointer to next testcase */
    143 };
    144 
    145 /*
    146 * KAT values for AES-256-CTR self-test.  These
    147 * values came from section 7 of RFC 6188.
    148 */
    149 /* clang-format off */
    150 static const uint8_t srtp_aes_icm_256_test_case_0_key[SRTP_AES_ICM_256_KEY_LEN_WSALT] = {
    151    0x57, 0xf8, 0x2f, 0xe3, 0x61, 0x3f, 0xd1, 0x70,
    152    0xa8, 0x5e, 0xc9, 0x3c, 0x40, 0xb1, 0xf0, 0x92,
    153    0x2e, 0xc4, 0xcb, 0x0d, 0xc0, 0x25, 0xb5, 0x82,
    154    0x72, 0x14, 0x7c, 0xc4, 0x38, 0x94, 0x4a, 0x98,
    155    0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
    156    0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd
    157 };
    158 /* clang-format on */
    159 
    160 /* clang-format off */
    161 static uint8_t srtp_aes_icm_256_test_case_0_nonce[16] = {
    162    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    163    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
    164 };
    165 /* clang-format on */
    166 
    167 /* clang-format off */
    168 static const uint8_t srtp_aes_icm_256_test_case_0_plaintext[32] =  {
    169    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    170    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    171    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    172    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    173 };
    174 /* clang-format on */
    175 
    176 /* clang-format off */
    177 static const uint8_t srtp_aes_icm_256_test_case_0_ciphertext[32] = {
    178    0x92, 0xbd, 0xd2, 0x8a, 0x93, 0xc3, 0xf5, 0x25,
    179    0x11, 0xc6, 0x77, 0xd0, 0x8b, 0x55, 0x15, 0xa4,
    180    0x9d, 0xa7, 0x1b, 0x23, 0x78, 0xa8, 0x54, 0xf6,
    181    0x70, 0x50, 0x75, 0x6d, 0xed, 0x16, 0x5b, 0xac
    182 };
    183 /* clang-format on */
    184 
    185 const srtp_cipher_test_case_t srtp_aes_icm_256_test_case_0 = {
    186    SRTP_AES_ICM_256_KEY_LEN_WSALT,          /* octets in key            */
    187    srtp_aes_icm_256_test_case_0_key,        /* key                      */
    188    srtp_aes_icm_256_test_case_0_nonce,      /* packet index             */
    189    32,                                      /* octets in plaintext      */
    190    srtp_aes_icm_256_test_case_0_plaintext,  /* plaintext                */
    191    32,                                      /* octets in ciphertext     */
    192    srtp_aes_icm_256_test_case_0_ciphertext, /* ciphertext               */
    193    0,                                       /* */
    194    NULL,                                    /* */
    195    0,                                       /* */
    196    NULL                                     /* pointer to next testcase */
    197 };
    198 
    199 /*
    200 * KAT values for AES self-test.  These
    201 * values we're derived from independent test code
    202 * using OpenSSL.
    203 */
    204 /* clang-format off */
    205 static const uint8_t srtp_aes_gcm_128_test_case_0_key[SRTP_AES_GCM_128_KEY_LEN_WSALT] = {
    206    0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
    207    0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
    208    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
    209    0x09, 0x0a, 0x0b, 0x0c,
    210 };
    211 /* clang-format on */
    212 
    213 /* clang-format off */
    214 static uint8_t srtp_aes_gcm_128_test_case_0_iv[12] = {
    215    0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
    216    0xde, 0xca, 0xf8, 0x88
    217 };
    218 /* clang-format on */
    219 
    220 /* clang-format off */
    221 static const uint8_t srtp_aes_gcm_128_test_case_0_plaintext[60] =  {
    222    0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
    223    0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
    224    0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
    225    0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
    226    0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
    227    0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
    228    0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
    229    0xba, 0x63, 0x7b, 0x39
    230 };
    231 
    232 /* clang-format off */
    233 static const uint8_t srtp_aes_gcm_128_test_case_0_aad[20] = {
    234    0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
    235    0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
    236    0xab, 0xad, 0xda, 0xd2
    237 };
    238 /* clang-format on */
    239 
    240 /* clang-format off */
    241 static const uint8_t srtp_aes_gcm_128_test_case_0_ciphertext[76] = {
    242    0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24,
    243    0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c,
    244    0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
    245    0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e,
    246    0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c,
    247    0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
    248    0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97,
    249    0x3d, 0x58, 0xe0, 0x91,
    250    /* the last 16 bytes are the tag */
    251    0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb,
    252    0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47,
    253 };
    254 /* clang-format on */
    255 
    256 static const srtp_cipher_test_case_t srtp_aes_gcm_128_test_case_0a = {
    257    SRTP_AES_GCM_128_KEY_LEN_WSALT,          /* octets in key            */
    258    srtp_aes_gcm_128_test_case_0_key,        /* key                      */
    259    srtp_aes_gcm_128_test_case_0_iv,         /* packet index             */
    260    60,                                      /* octets in plaintext      */
    261    srtp_aes_gcm_128_test_case_0_plaintext,  /* plaintext                */
    262    68,                                      /* octets in ciphertext     */
    263    srtp_aes_gcm_128_test_case_0_ciphertext, /* ciphertext  + tag        */
    264    20,                                      /* octets in AAD            */
    265    srtp_aes_gcm_128_test_case_0_aad,        /* AAD                      */
    266    8,                                       /* */
    267    NULL                                     /* pointer to next testcase */
    268 };
    269 
    270 const srtp_cipher_test_case_t srtp_aes_gcm_128_test_case_0 = {
    271    SRTP_AES_GCM_128_KEY_LEN_WSALT,          /* octets in key            */
    272    srtp_aes_gcm_128_test_case_0_key,        /* key                      */
    273    srtp_aes_gcm_128_test_case_0_iv,         /* packet index             */
    274    60,                                      /* octets in plaintext      */
    275    srtp_aes_gcm_128_test_case_0_plaintext,  /* plaintext                */
    276    76,                                      /* octets in ciphertext     */
    277    srtp_aes_gcm_128_test_case_0_ciphertext, /* ciphertext  + tag        */
    278    20,                                      /* octets in AAD            */
    279    srtp_aes_gcm_128_test_case_0_aad,        /* AAD                      */
    280    16,                                      /* */
    281    &srtp_aes_gcm_128_test_case_0a           /* pointer to next testcase */
    282 };
    283 
    284 /* clang-format off */
    285 static const uint8_t srtp_aes_gcm_256_test_case_0_key[SRTP_AES_GCM_256_KEY_LEN_WSALT] = {
    286    0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
    287    0xa5, 0x59, 0x09, 0xc5, 0x54, 0x66, 0x93, 0x1c,
    288    0xaf, 0xf5, 0x26, 0x9a, 0x21, 0xd5, 0x14, 0xb2,
    289    0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08,
    290    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
    291    0x09, 0x0a, 0x0b, 0x0c,
    292 };
    293 /* clang-format on */
    294 
    295 /* clang-format off */
    296 static uint8_t srtp_aes_gcm_256_test_case_0_iv[12] = {
    297    0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad,
    298    0xde, 0xca, 0xf8, 0x88
    299 };
    300 /* clang-format on */
    301 
    302 /* clang-format off */
    303 static const uint8_t srtp_aes_gcm_256_test_case_0_plaintext[60] =  {
    304    0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
    305    0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
    306    0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
    307    0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
    308    0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
    309    0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
    310    0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
    311    0xba, 0x63, 0x7b, 0x39
    312 };
    313 /* clang-format on */
    314 
    315 /* clang-format off */
    316 static const uint8_t srtp_aes_gcm_256_test_case_0_aad[20] = {
    317    0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
    318    0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
    319    0xab, 0xad, 0xda, 0xd2
    320 };
    321 /* clang-format on */
    322 
    323 /* clang-format off */
    324 static const uint8_t srtp_aes_gcm_256_test_case_0_ciphertext[76] = {
    325    0x0b, 0x11, 0xcf, 0xaf, 0x68, 0x4d, 0xae, 0x46,
    326    0xc7, 0x90, 0xb8, 0x8e, 0xb7, 0x6a, 0x76, 0x2a,
    327    0x94, 0x82, 0xca, 0xab, 0x3e, 0x39, 0xd7, 0x86,
    328    0x1b, 0xc7, 0x93, 0xed, 0x75, 0x7f, 0x23, 0x5a,
    329    0xda, 0xfd, 0xd3, 0xe2, 0x0e, 0x80, 0x87, 0xa9,
    330    0x6d, 0xd7, 0xe2, 0x6a, 0x7d, 0x5f, 0xb4, 0x80,
    331    0xef, 0xef, 0xc5, 0x29, 0x12, 0xd1, 0xaa, 0x10,
    332    0x09, 0xc9, 0x86, 0xc1,
    333    /* the last 16 bytes are the tag */
    334    0x45, 0xbc, 0x03, 0xe6, 0xe1, 0xac, 0x0a, 0x9f,
    335    0x81, 0xcb, 0x8e, 0x5b, 0x46, 0x65, 0x63, 0x1d,
    336 };
    337 /* clang-format on */
    338 
    339 static const srtp_cipher_test_case_t srtp_aes_gcm_256_test_case_0a = {
    340    SRTP_AES_GCM_256_KEY_LEN_WSALT,          /* octets in key            */
    341    srtp_aes_gcm_256_test_case_0_key,        /* key                      */
    342    srtp_aes_gcm_256_test_case_0_iv,         /* packet index             */
    343    60,                                      /* octets in plaintext      */
    344    srtp_aes_gcm_256_test_case_0_plaintext,  /* plaintext                */
    345    68,                                      /* octets in ciphertext     */
    346    srtp_aes_gcm_256_test_case_0_ciphertext, /* ciphertext  + tag        */
    347    20,                                      /* octets in AAD            */
    348    srtp_aes_gcm_256_test_case_0_aad,        /* AAD                      */
    349    8,                                       /* */
    350    NULL                                     /* pointer to next testcase */
    351 };
    352 
    353 const srtp_cipher_test_case_t srtp_aes_gcm_256_test_case_0 = {
    354    SRTP_AES_GCM_256_KEY_LEN_WSALT,          /* octets in key            */
    355    srtp_aes_gcm_256_test_case_0_key,        /* key                      */
    356    srtp_aes_gcm_256_test_case_0_iv,         /* packet index             */
    357    60,                                      /* octets in plaintext      */
    358    srtp_aes_gcm_256_test_case_0_plaintext,  /* plaintext                */
    359    76,                                      /* octets in ciphertext     */
    360    srtp_aes_gcm_256_test_case_0_ciphertext, /* ciphertext  + tag        */
    361    20,                                      /* octets in AAD            */
    362    srtp_aes_gcm_256_test_case_0_aad,        /* AAD                      */
    363    16,                                      /* */
    364    &srtp_aes_gcm_256_test_case_0a           /* pointer to next testcase */
    365 };