]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-prf_tls12-test.c
switching to dedicated endian switching function
[arm-crypto-lib.git] / test_src / main-prf_tls12-test.c
1 /* main-prf_tls12-test.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /*
20  * DSA test-suit
21  *
22 */
23
24 #include "main-test-common.h"
25 #include "prf_tls12.h"
26 #include "hashfunction_descriptor.h"
27 #include "hfal_sha512.h"
28 #include "hfal_sha256.h"
29 const char* algo_name = "PRF-TLS1.2";
30
31 /*****************************************************************************
32  *  additional validation-functions                                                                                      *
33  *****************************************************************************/
34
35 /*
36 # Generating 100 bytes of pseudo-randomness using TLS1.2PRF-SHA256
37 Secret (16 bytes):
38 0000    9b be 43 6b a9 40 f0 17    ..Ck....
39 0008    b1 76 52 84 9a 71 db 35    .vR..q.5
40
41 Seed (16 bytes):
42 0000    a0 ba 9f 93 6c da 31 18    ....l.1.
43 0008    27 a6 f7 96 ff d5 19 8c    ........
44
45 Label (10 bytes):
46 0000    74 65 73 74 20 6c 61 62    test lab
47 0008    65 6c                      el
48
49 Output (100 bytes):
50 0000    e3 f2 29 ba 72 7b e1 7b    ....r...
51 0008    8d 12 26 20 55 7c d4 53    ... U..S
52 0010    c2 aa b2 1d 07 c3 d4 95    ........
53 0018    32 9b 52 d4 e6 1e db 5a    2.R....Z
54 0020    6b 30 17 91 e9 0d 35 c9    k0....5.
55 0028    c9 a4 6b 4e 14 ba f9 af    ..kN....
56 0030    0f a0 22 f7 07 7d ef 17    ........
57 0038    ab fd 37 97 c0 56 4b ab    ..7..VK.
58 0040    4f bc 91 66 6e 9d ef 9b    O..fn...
59 0048    97 fc e3 4f 79 67 89 ba    ...Oyg..
60 0050    a4 80 82 d1 22 ee 42 c5    ......B.
61 0058    a7 2e 5a 51 10 ff f7 01    ..ZQ....
62 0060    87 34 7b 66                .4.f
63  */
64
65
66 const char test_label[] = "test label";
67
68 void test_prf(const hfdesc_t* hash, const void* secret, const void* seed, uint16_t out_length){
69         prf_tls12_ctx_t ctx;
70         uint8_t buffer[out_length];
71         prf_tls12_init_w_label(&ctx, hash, secret, 16*8, test_label, strlen(test_label), seed, 16*8);
72         cli_putstr("\r\n== Testing PRF-TLSv1.2 with ");
73         cli_putstr(hash->name);
74         cli_putstr(" ==\r\n");
75         prf_tls12_fill(buffer, out_length, &ctx);
76         cli_hexdump_block(buffer, out_length, 4, 8);
77         prf_tls12_free(&ctx);
78 }
79
80 void test_sha256(void){
81         const uint8_t secret[] = {
82                 0x9b, 0xbe, 0x43, 0x6b, 0xa9, 0x40, 0xf0, 0x17,
83                 0xb1, 0x76, 0x52, 0x84, 0x9a, 0x71, 0xdb, 0x35
84         };
85
86         const uint8_t seed[] = {
87                 0xa0, 0xba, 0x9f, 0x93, 0x6c, 0xda, 0x31, 0x18,
88                 0x27, 0xa6, 0xf7, 0x96, 0xff, 0xd5, 0x19, 0x8c
89         };
90         test_prf(&sha256_desc, secret, seed, 100);
91 }
92
93 void test_sha512(void){
94
95
96 const uint8_t secret[] = {
97                 0xb0, 0x32, 0x35, 0x23, 0xc1, 0x85, 0x35, 0x99,
98                 0x58, 0x4d, 0x88, 0x56, 0x8b, 0xbb, 0x05, 0xeb
99         };
100
101 const uint8_t seed[] = {
102                 0xd4, 0x64, 0x0e, 0x12, 0xe4, 0xbc, 0xdb, 0xfb,
103                 0x43, 0x7f, 0x03, 0xe6, 0xae, 0x41, 0x8e, 0xe5,
104         };
105         test_prf(&sha512_desc, secret, seed, 196);
106 }
107
108 /*****************************************************************************
109  *  main                                                                                                                                         *
110  *****************************************************************************/
111
112 const char echo_test_str[]     = "echo-test";
113 const char test_sha256_str[]   = "test-sha256";
114 const char test_sha512_str[]   = "test-sha512";
115 //const char performance_str[]   = "performance";
116 const char echo_str[]          = "echo";
117
118 cmdlist_entry_t cmdlist[] = {
119         { test_sha256_str,      NULL, test_sha256                   },
120         { test_sha512_str,      NULL, test_sha512                   },
121 //      { performance_str,      NULL, testrun_performance_bigint    },
122         { echo_str,         (void*)1, (void_fpt)echo_ctrl           },
123         { NULL,                 NULL, NULL                          }
124 };
125
126 int main (void){
127         main_setup();
128
129         for(;;){
130                 welcome_msg(algo_name);
131                 cmd_interface(cmdlist);
132         }
133 }