1*2ccfa855SEd Maste /*
2*2ccfa855SEd Maste * Copyright (c) 2022 Yubico AB. All rights reserved.
3*2ccfa855SEd Maste * Use of this source code is governed by a BSD-style
4*2ccfa855SEd Maste * license that can be found in the LICENSE file.
5*2ccfa855SEd Maste * SPDX-License-Identifier: BSD-2-Clause
6*2ccfa855SEd Maste */
7*2ccfa855SEd Maste
8*2ccfa855SEd Maste #undef NDEBUG
9*2ccfa855SEd Maste
10*2ccfa855SEd Maste #include <assert.h>
11*2ccfa855SEd Maste #include <string.h>
12*2ccfa855SEd Maste
13*2ccfa855SEd Maste #include <openssl/sha.h>
14*2ccfa855SEd Maste
15*2ccfa855SEd Maste #define _FIDO_INTERNAL
16*2ccfa855SEd Maste
17*2ccfa855SEd Maste #include <fido.h>
18*2ccfa855SEd Maste
19*2ccfa855SEd Maste /*
20*2ccfa855SEd Maste * zlib compressed data (RFC1950); see https://www.ietf.org/rfc/rfc6713.txt
21*2ccfa855SEd Maste */
22*2ccfa855SEd Maste static /* const */ unsigned char rfc1950_blob[694] = {
23*2ccfa855SEd Maste 0x78, 0x9c, 0xb5, 0x52, 0x3b, 0x6f, 0xdb, 0x30,
24*2ccfa855SEd Maste 0x10, 0xde, 0xf5, 0x2b, 0x0e, 0x99, 0x12, 0x40,
25*2ccfa855SEd Maste 0x75, 0x13, 0x4f, 0x45, 0x3b, 0xd1, 0x12, 0x6d,
26*2ccfa855SEd Maste 0x1d, 0x20, 0x8b, 0x2a, 0x49, 0xd9, 0xf5, 0x28,
27*2ccfa855SEd Maste 0x4b, 0x4c, 0x42, 0xc0, 0x12, 0x03, 0x3d, 0x12,
28*2ccfa855SEd Maste 0xe4, 0xdf, 0xf7, 0xc8, 0x3a, 0x88, 0xd3, 0x0c,
29*2ccfa855SEd Maste 0x9d, 0xea, 0xc1, 0x3e, 0xf3, 0x8e, 0xdf, 0xeb,
30*2ccfa855SEd Maste 0x98, 0xb8, 0xa7, 0xd7, 0xc1, 0x3e, 0x3c, 0x4e,
31*2ccfa855SEd Maste 0x70, 0xdd, 0xdc, 0xc0, 0xf2, 0xf6, 0xee, 0xdb,
32*2ccfa855SEd Maste 0x97, 0xe5, 0xed, 0x72, 0x09, 0x87, 0xf9, 0x68,
33*2ccfa855SEd Maste 0x1b, 0x07, 0x6c, 0xb5, 0x00, 0x76, 0x3a, 0x41,
34*2ccfa855SEd Maste 0x18, 0x19, 0x61, 0x30, 0xa3, 0x19, 0x9e, 0x4d,
35*2ccfa855SEd Maste 0xbb, 0x88, 0x22, 0x69, 0x5a, 0x3b, 0x4e, 0x83,
36*2ccfa855SEd Maste 0x3d, 0xce, 0x93, 0x75, 0x3d, 0xd4, 0x7d, 0x0b,
37*2ccfa855SEd Maste 0xf3, 0x68, 0xc0, 0xf6, 0x30, 0xba, 0x79, 0x68,
38*2ccfa855SEd Maste 0x4c, 0x38, 0x39, 0xda, 0xbe, 0x1e, 0x5e, 0xe1,
39*2ccfa855SEd Maste 0xde, 0x0d, 0xdd, 0x18, 0xc3, 0x8b, 0x9d, 0x1e,
40*2ccfa855SEd Maste 0xc1, 0x0d, 0xe1, 0xd7, 0xcd, 0x53, 0xd4, 0xb9,
41*2ccfa855SEd Maste 0xd6, 0xde, 0xdb, 0xa6, 0xf6, 0x00, 0x31, 0xd4,
42*2ccfa855SEd Maste 0x83, 0x81, 0x27, 0x33, 0x74, 0x76, 0x9a, 0x4c,
43*2ccfa855SEd Maste 0x0b, 0x4f, 0x83, 0x7b, 0xb6, 0x2d, 0x15, 0xd3,
44*2ccfa855SEd Maste 0x63, 0x3d, 0xd1, 0x97, 0x21, 0x90, 0xd3, 0xc9,
45*2ccfa855SEd Maste 0xbd, 0xd8, 0xfe, 0x01, 0x1a, 0xd7, 0xb7, 0xd6,
46*2ccfa855SEd Maste 0x5f, 0x1a, 0xfd, 0xa5, 0xa8, 0x33, 0xd3, 0xf7,
47*2ccfa855SEd Maste 0x28, 0x02, 0x80, 0xbb, 0x05, 0x7c, 0x54, 0x35,
48*2ccfa855SEd Maste 0x82, 0xbb, 0x7f, 0x93, 0xd3, 0xb8, 0xd6, 0x40,
49*2ccfa855SEd Maste 0x37, 0x8f, 0x13, 0x99, 0x98, 0x6a, 0x92, 0xe9,
50*2ccfa855SEd Maste 0x31, 0xeb, 0xa3, 0x7b, 0xf6, 0xad, 0x73, 0x06,
51*2ccfa855SEd Maste 0x1e, 0x84, 0x3e, 0xbd, 0x9b, 0x6c, 0x63, 0x62,
52*2ccfa855SEd Maste 0x9a, 0xb0, 0x23, 0x9c, 0x08, 0xcf, 0xc3, 0x5c,
53*2ccfa855SEd Maste 0x92, 0xf6, 0xed, 0x5f, 0x8a, 0x88, 0xb4, 0x39,
54*2ccfa855SEd Maste 0xd5, 0xb6, 0x33, 0xc3, 0xc2, 0x63, 0x2c, 0x3f,
55*2ccfa855SEd Maste 0x0b, 0x21, 0xc2, 0x8b, 0x30, 0xde, 0x84, 0x90,
56*2ccfa855SEd Maste 0xcb, 0x76, 0x26, 0x71, 0xff, 0x47, 0x0b, 0x91,
57*2ccfa855SEd Maste 0x9e, 0x51, 0xfc, 0x44, 0xeb, 0x9a, 0xb9, 0x33,
58*2ccfa855SEd Maste 0xfd, 0x54, 0xbf, 0xed, 0xeb, 0x2b, 0xad, 0xc2,
59*2ccfa855SEd Maste 0x51, 0x67, 0x80, 0xae, 0x9e, 0xcc, 0x60, 0xeb,
60*2ccfa855SEd Maste 0xd3, 0xf8, 0x1e, 0x7b, 0xd8, 0x15, 0x35, 0xcf,
61*2ccfa855SEd Maste 0x00, 0x97, 0x66, 0x68, 0xf9, 0x3a, 0x43, 0x05,
62*2ccfa855SEd Maste 0x4a, 0xac, 0xf5, 0x9e, 0x49, 0x0e, 0x54, 0x97,
63*2ccfa855SEd Maste 0x52, 0xec, 0x30, 0xe5, 0x29, 0xac, 0x0e, 0xa0,
64*2ccfa855SEd Maste 0x33, 0x0e, 0x89, 0x28, 0x0f, 0x12, 0x37, 0x99,
65*2ccfa855SEd Maste 0x86, 0x4c, 0xe4, 0x29, 0x97, 0x0a, 0x58, 0x91,
66*2ccfa855SEd Maste 0xd2, 0x69, 0xa1, 0x25, 0xae, 0x2a, 0x2d, 0xa4,
67*2ccfa855SEd Maste 0x8a, 0xae, 0x98, 0xa2, 0x9b, 0x57, 0xa1, 0xc1,
68*2ccfa855SEd Maste 0x8a, 0x03, 0xf0, 0x5f, 0xa5, 0xe4, 0x4a, 0x81,
69*2ccfa855SEd Maste 0x90, 0x80, 0xdb, 0x32, 0x47, 0x02, 0x23, 0x74,
70*2ccfa855SEd Maste 0xc9, 0x0a, 0x8d, 0x5c, 0xc5, 0x80, 0x45, 0x92,
71*2ccfa855SEd Maste 0x57, 0x29, 0x16, 0x9b, 0x18, 0x08, 0x00, 0x0a,
72*2ccfa855SEd Maste 0xa1, 0xa3, 0x1c, 0xb7, 0xa8, 0x69, 0x4c, 0x8b,
73*2ccfa855SEd Maste 0x38, 0x90, 0x7e, 0xbe, 0x06, 0x62, 0x0d, 0x5b,
74*2ccfa855SEd Maste 0x2e, 0x93, 0x8c, 0xfe, 0xb2, 0x15, 0xe6, 0xa8,
75*2ccfa855SEd Maste 0x0f, 0x81, 0x6f, 0x8d, 0xba, 0xf0, 0x5c, 0x6b,
76*2ccfa855SEd Maste 0x21, 0x23, 0x06, 0x25, 0x93, 0x1a, 0x93, 0x2a,
77*2ccfa855SEd Maste 0x67, 0x12, 0xca, 0x4a, 0x96, 0x42, 0x71, 0xf0,
78*2ccfa855SEd Maste 0xb6, 0x52, 0x54, 0x49, 0xce, 0x70, 0xcb, 0xd3,
79*2ccfa855SEd Maste 0x05, 0xb1, 0x13, 0x23, 0xf0, 0x1d, 0x2f, 0x34,
80*2ccfa855SEd Maste 0xa8, 0x8c, 0xe5, 0xf9, 0x47, 0x97, 0xd1, 0x1f,
81*2ccfa855SEd Maste 0x97, 0x5e, 0xfb, 0xa5, 0x47, 0x58, 0x71, 0xc8,
82*2ccfa855SEd Maste 0x91, 0xad, 0x72, 0xee, 0x99, 0x82, 0xcb, 0x14,
83*2ccfa855SEd Maste 0x25, 0x4f, 0xb4, 0xb7, 0xf3, 0x5e, 0x25, 0x94,
84*2ccfa855SEd Maste 0x1c, 0xe9, 0xcb, 0xe3, 0x48, 0x95, 0x3c, 0x41,
85*2ccfa855SEd Maste 0x2a, 0x28, 0x0c, 0x4e, 0x66, 0x98, 0x3c, 0xc4,
86*2ccfa855SEd Maste 0x67, 0x4c, 0xc5, 0x7f, 0x56, 0x34, 0x44, 0x4d,
87*2ccfa855SEd Maste 0x48, 0xd9, 0x96, 0x6d, 0xc8, 0xdb, 0xf5, 0x3f,
88*2ccfa855SEd Maste 0x22, 0xa1, 0x9d, 0x24, 0x95, 0xe4, 0x5b, 0xaf,
89*2ccfa855SEd Maste 0x99, 0x72, 0x50, 0xd5, 0x4a, 0x69, 0xd4, 0x95,
90*2ccfa855SEd Maste 0xe6, 0xb0, 0x11, 0x22, 0x0d, 0x41, 0x2b, 0x2e,
91*2ccfa855SEd Maste 0x77, 0x98, 0x70, 0xf5, 0x03, 0x72, 0xa1, 0x42,
92*2ccfa855SEd Maste 0x5a, 0x95, 0xe2, 0x71, 0x94, 0x32, 0xcd, 0x02,
93*2ccfa855SEd Maste 0x31, 0x41, 0x50, 0x54, 0xd4, 0xa6, 0x7a, 0x55,
94*2ccfa855SEd Maste 0x29, 0x0c, 0xa1, 0x61, 0xa1, 0xb9, 0x94, 0x55,
95*2ccfa855SEd Maste 0xa9, 0x51, 0x14, 0x37, 0xb4, 0xdf, 0x3d, 0xc5,
96*2ccfa855SEd Maste 0x42, 0x1a, 0x19, 0x5d, 0x4d, 0x43, 0xba, 0xa2,
97*2ccfa855SEd Maste 0xf0, 0x56, 0xe9, 0x91, 0x70, 0x21, 0x0f, 0x1e,
98*2ccfa855SEd Maste 0xd4, 0x67, 0x10, 0xc2, 0x8f, 0x61, 0x9f, 0x71,
99*2ccfa855SEd Maste 0x3a, 0x97, 0x3e, 0xd0, 0x90, 0x14, 0xf3, 0x11,
100*2ccfa855SEd Maste 0x28, 0x4a, 0x2c, 0xd1, 0x97, 0x63, 0xc4, 0x47,
101*2ccfa855SEd Maste 0x01, 0xea, 0xe8, 0xdd, 0x23, 0x14, 0x7c, 0x93,
102*2ccfa855SEd Maste 0xe3, 0x86, 0x17, 0x09, 0xf7, 0x5d, 0xe1, 0x51,
103*2ccfa855SEd Maste 0xf6, 0xa8, 0xf8, 0x0d, 0xed, 0x0a, 0x95, 0x1f,
104*2ccfa855SEd Maste 0xc0, 0x40, 0x4b, 0xdb, 0x27, 0xce, 0x2a, 0x58,
105*2ccfa855SEd Maste 0xf6, 0x3b, 0x22, 0x55, 0x51, 0x28, 0x2f, 0x5e,
106*2ccfa855SEd Maste 0x6c, 0x1c, 0x36, 0x09, 0xb8, 0x06, 0x96, 0xee,
107*2ccfa855SEd Maste 0xd0, 0xcb, 0x3e, 0x0f, 0xd3, 0xee, 0x15, 0x9e,
108*2ccfa855SEd Maste 0xdf, 0x49, 0x88, 0x2c, 0xc9, 0xce, 0x71, 0x2f,
109*2ccfa855SEd Maste 0xa2, 0xdf, 0xdf, 0xd7, 0x8e, 0x9c,
110*2ccfa855SEd Maste };
111*2ccfa855SEd Maste
112*2ccfa855SEd Maste /*
113*2ccfa855SEd Maste * expected sha256 of rfc1950_blob after decompression
114*2ccfa855SEd Maste */
115*2ccfa855SEd Maste static const unsigned char rfc1950_blob_hash[SHA256_DIGEST_LENGTH] = {
116*2ccfa855SEd Maste 0x61, 0xc0, 0x4e, 0x14, 0x01, 0xb6, 0xc5, 0x2d,
117*2ccfa855SEd Maste 0xba, 0x15, 0xf6, 0x27, 0x4c, 0xa1, 0xcc, 0xfc,
118*2ccfa855SEd Maste 0x39, 0xed, 0xd7, 0x12, 0xb6, 0x02, 0x3d, 0xb6,
119*2ccfa855SEd Maste 0xd9, 0x85, 0xd0, 0x10, 0x9f, 0xe9, 0x3e, 0x75,
120*2ccfa855SEd Maste
121*2ccfa855SEd Maste };
122*2ccfa855SEd Maste
123*2ccfa855SEd Maste static const size_t rfc1950_blob_origsiz = 1322;
124*2ccfa855SEd Maste
125*2ccfa855SEd Maste static /* const */ unsigned char random_words[515] = {
126*2ccfa855SEd Maste 0x61, 0x74, 0x68, 0x69, 0x72, 0x73, 0x74, 0x20,
127*2ccfa855SEd Maste 0x54, 0x68, 0x6f, 0x20, 0x63, 0x6f, 0x74, 0x20,
128*2ccfa855SEd Maste 0x73, 0x70, 0x6f, 0x66, 0x66, 0x79, 0x20, 0x4a,
129*2ccfa855SEd Maste 0x61, 0x76, 0x61, 0x6e, 0x20, 0x62, 0x72, 0x65,
130*2ccfa855SEd Maste 0x64, 0x65, 0x73, 0x20, 0x4c, 0x41, 0x4d, 0x20,
131*2ccfa855SEd Maste 0x6d, 0x69, 0x73, 0x2d, 0x68, 0x75, 0x6d, 0x69,
132*2ccfa855SEd Maste 0x6c, 0x69, 0x74, 0x79, 0x20, 0x73, 0x70, 0x69,
133*2ccfa855SEd Maste 0x67, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x76, 0x6f,
134*2ccfa855SEd Maste 0x6c, 0x74, 0x69, 0x6e, 0x67, 0x6c, 0x79, 0x20,
135*2ccfa855SEd Maste 0x49, 0x6f, 0x64, 0x61, 0x6d, 0x6f, 0x65, 0x62,
136*2ccfa855SEd Maste 0x61, 0x20, 0x68, 0x79, 0x70, 0x6f, 0x68, 0x79,
137*2ccfa855SEd Maste 0x64, 0x72, 0x6f, 0x63, 0x68, 0x6c, 0x6f, 0x72,
138*2ccfa855SEd Maste 0x69, 0x61, 0x20, 0x76, 0x6f, 0x6c, 0x75, 0x6d,
139*2ccfa855SEd Maste 0x65, 0x74, 0x74, 0x65, 0x20, 0x61, 0x63, 0x72,
140*2ccfa855SEd Maste 0x69, 0x64, 0x69, 0x6e, 0x65, 0x20, 0x68, 0x6f,
141*2ccfa855SEd Maste 0x77, 0x6c, 0x20, 0x45, 0x75, 0x72, 0x79, 0x67,
142*2ccfa855SEd Maste 0x61, 0x65, 0x61, 0x6e, 0x20, 0x63, 0x6f, 0x6e,
143*2ccfa855SEd Maste 0x63, 0x65, 0x72, 0x74, 0x69, 0x6e, 0x69, 0x73,
144*2ccfa855SEd Maste 0x74, 0x20, 0x74, 0x65, 0x74, 0x72, 0x61, 0x70,
145*2ccfa855SEd Maste 0x6c, 0x6f, 0x69, 0x64, 0x20, 0x61, 0x75, 0x78,
146*2ccfa855SEd Maste 0x65, 0x74, 0x69, 0x63, 0x61, 0x6c, 0x20, 0x72,
147*2ccfa855SEd Maste 0x69, 0x70, 0x65, 0x2d, 0x67, 0x72, 0x6f, 0x77,
148*2ccfa855SEd Maste 0x6e, 0x20, 0x63, 0x6f, 0x6e, 0x63, 0x75, 0x72,
149*2ccfa855SEd Maste 0x72, 0x69, 0x6e, 0x67, 0x20, 0x6d, 0x79, 0x63,
150*2ccfa855SEd Maste 0x6f, 0x63, 0x65, 0x63, 0x69, 0x64, 0x69, 0x75,
151*2ccfa855SEd Maste 0x6d, 0x20, 0x50, 0x65, 0x64, 0x65, 0x72, 0x73,
152*2ccfa855SEd Maste 0x6f, 0x6e, 0x20, 0x74, 0x72, 0x61, 0x64, 0x69,
153*2ccfa855SEd Maste 0x74, 0x69, 0x6f, 0x6e, 0x2d, 0x62, 0x6f, 0x75,
154*2ccfa855SEd Maste 0x6e, 0x64, 0x20, 0x4c, 0x65, 0x6e, 0x67, 0x6c,
155*2ccfa855SEd Maste 0x65, 0x6e, 0x20, 0x70, 0x72, 0x65, 0x73, 0x62,
156*2ccfa855SEd Maste 0x79, 0x74, 0x65, 0x72, 0x61, 0x74, 0x65, 0x20,
157*2ccfa855SEd Maste 0x6c, 0x65, 0x63, 0x79, 0x74, 0x68, 0x69, 0x73,
158*2ccfa855SEd Maste 0x20, 0x63, 0x68, 0x61, 0x72, 0x61, 0x64, 0x72,
159*2ccfa855SEd Maste 0x69, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x61,
160*2ccfa855SEd Maste 0x6c, 0x6c, 0x6f, 0x6b, 0x75, 0x72, 0x74, 0x69,
161*2ccfa855SEd Maste 0x63, 0x20, 0x75, 0x6e, 0x64, 0x69, 0x76, 0x69,
162*2ccfa855SEd Maste 0x73, 0x69, 0x76, 0x65, 0x6c, 0x79, 0x20, 0x70,
163*2ccfa855SEd Maste 0x73, 0x79, 0x63, 0x68, 0x6f, 0x6b, 0x79, 0x6d,
164*2ccfa855SEd Maste 0x65, 0x20, 0x75, 0x6e, 0x64, 0x65, 0x72, 0x73,
165*2ccfa855SEd Maste 0x74, 0x61, 0x6e, 0x64, 0x61, 0x62, 0x6c, 0x65,
166*2ccfa855SEd Maste 0x6e, 0x65, 0x73, 0x73, 0x20, 0x63, 0x75, 0x6c,
167*2ccfa855SEd Maste 0x74, 0x69, 0x73, 0x68, 0x20, 0x52, 0x65, 0x69,
168*2ccfa855SEd Maste 0x63, 0x68, 0x73, 0x74, 0x61, 0x67, 0x20, 0x75,
169*2ccfa855SEd Maste 0x6e, 0x63, 0x68, 0x6c, 0x6f, 0x72, 0x69, 0x6e,
170*2ccfa855SEd Maste 0x61, 0x74, 0x65, 0x64, 0x20, 0x6c, 0x6f, 0x67,
171*2ccfa855SEd Maste 0x6f, 0x67, 0x72, 0x61, 0x70, 0x68, 0x65, 0x72,
172*2ccfa855SEd Maste 0x20, 0x4c, 0x61, 0x69, 0x74, 0x68, 0x20, 0x74,
173*2ccfa855SEd Maste 0x77, 0x6f, 0x2d, 0x66, 0x61, 0x63, 0x65, 0x20,
174*2ccfa855SEd Maste 0x4d, 0x75, 0x70, 0x68, 0x72, 0x69, 0x64, 0x20,
175*2ccfa855SEd Maste 0x70, 0x72, 0x6f, 0x72, 0x65, 0x63, 0x69, 0x70,
176*2ccfa855SEd Maste 0x72, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e,
177*2ccfa855SEd Maste 0x20, 0x6c, 0x69, 0x62, 0x72, 0x65, 0x74, 0x74,
178*2ccfa855SEd Maste 0x69, 0x73, 0x74, 0x20, 0x49, 0x62, 0x69, 0x62,
179*2ccfa855SEd Maste 0x69, 0x6f, 0x20, 0x72, 0x65, 0x67, 0x72, 0x65,
180*2ccfa855SEd Maste 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x63,
181*2ccfa855SEd Maste 0x6f, 0x6e, 0x64, 0x69, 0x67, 0x6e, 0x6e, 0x65,
182*2ccfa855SEd Maste 0x73, 0x73, 0x20, 0x77, 0x68, 0x69, 0x74, 0x65,
183*2ccfa855SEd Maste 0x2d, 0x62, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x65,
184*2ccfa855SEd Maste 0x64, 0x20, 0x73, 0x79, 0x6e, 0x61, 0x70, 0x74,
185*2ccfa855SEd Maste 0x65, 0x6e, 0x65, 0x20, 0x68, 0x6f, 0x6c, 0x6f,
186*2ccfa855SEd Maste 0x6d, 0x6f, 0x72, 0x70, 0x68, 0x20, 0x6d, 0x6f,
187*2ccfa855SEd Maste 0x75, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x20, 0x4d,
188*2ccfa855SEd Maste 0x49, 0x54, 0x53, 0x20, 0x4c, 0x75, 0x6b, 0x61,
189*2ccfa855SEd Maste 0x73, 0x68, 0x20, 0x48, 0x6f, 0x72, 0x73, 0x65,
190*2ccfa855SEd Maste 0x79, 0x20, 0x0a,
191*2ccfa855SEd Maste };
192*2ccfa855SEd Maste
193*2ccfa855SEd Maste static void
rfc1950_inflate(void)194*2ccfa855SEd Maste rfc1950_inflate(void)
195*2ccfa855SEd Maste {
196*2ccfa855SEd Maste fido_blob_t in, out, dgst;
197*2ccfa855SEd Maste
198*2ccfa855SEd Maste memset(&in, 0, sizeof(in));
199*2ccfa855SEd Maste memset(&out, 0, sizeof(out));
200*2ccfa855SEd Maste memset(&dgst, 0, sizeof(dgst));
201*2ccfa855SEd Maste in.ptr = rfc1950_blob;
202*2ccfa855SEd Maste in.len = sizeof(rfc1950_blob);
203*2ccfa855SEd Maste
204*2ccfa855SEd Maste assert(fido_uncompress(&out, &in, rfc1950_blob_origsiz) == FIDO_OK);
205*2ccfa855SEd Maste assert(out.len == rfc1950_blob_origsiz);
206*2ccfa855SEd Maste assert(fido_sha256(&dgst, out.ptr, out.len) == 0);
207*2ccfa855SEd Maste assert(dgst.len == sizeof(rfc1950_blob_hash));
208*2ccfa855SEd Maste assert(memcmp(rfc1950_blob_hash, dgst.ptr, dgst.len) == 0);
209*2ccfa855SEd Maste
210*2ccfa855SEd Maste free(out.ptr);
211*2ccfa855SEd Maste free(dgst.ptr);
212*2ccfa855SEd Maste }
213*2ccfa855SEd Maste
214*2ccfa855SEd Maste static void
rfc1951_inflate(void)215*2ccfa855SEd Maste rfc1951_inflate(void)
216*2ccfa855SEd Maste {
217*2ccfa855SEd Maste fido_blob_t in, out, dgst;
218*2ccfa855SEd Maste
219*2ccfa855SEd Maste memset(&in, 0, sizeof(in));
220*2ccfa855SEd Maste memset(&out, 0, sizeof(out));
221*2ccfa855SEd Maste memset(&dgst, 0, sizeof(dgst));
222*2ccfa855SEd Maste in.ptr = rfc1950_blob + 2; /* trim header */
223*2ccfa855SEd Maste in.len = sizeof(rfc1950_blob) - 6; /* trim header (2), checksum (4) */
224*2ccfa855SEd Maste
225*2ccfa855SEd Maste assert(fido_uncompress(&out, &in, rfc1950_blob_origsiz) == FIDO_OK);
226*2ccfa855SEd Maste assert(out.len == rfc1950_blob_origsiz);
227*2ccfa855SEd Maste assert(fido_sha256(&dgst, out.ptr, out.len) == 0);
228*2ccfa855SEd Maste assert(dgst.len == sizeof(rfc1950_blob_hash));
229*2ccfa855SEd Maste assert(memcmp(rfc1950_blob_hash, dgst.ptr, dgst.len) == 0);
230*2ccfa855SEd Maste
231*2ccfa855SEd Maste free(out.ptr);
232*2ccfa855SEd Maste free(dgst.ptr);
233*2ccfa855SEd Maste }
234*2ccfa855SEd Maste
235*2ccfa855SEd Maste static void
rfc1951_reinflate(void)236*2ccfa855SEd Maste rfc1951_reinflate(void)
237*2ccfa855SEd Maste {
238*2ccfa855SEd Maste fido_blob_t in, out;
239*2ccfa855SEd Maste
240*2ccfa855SEd Maste memset(&in, 0, sizeof(in));
241*2ccfa855SEd Maste memset(&out, 0, sizeof(out));
242*2ccfa855SEd Maste in.ptr = random_words;
243*2ccfa855SEd Maste in.len = sizeof(random_words);
244*2ccfa855SEd Maste
245*2ccfa855SEd Maste assert(fido_compress(&out, &in) == FIDO_OK);
246*2ccfa855SEd Maste
247*2ccfa855SEd Maste in.ptr = out.ptr;
248*2ccfa855SEd Maste in.len = out.len;
249*2ccfa855SEd Maste
250*2ccfa855SEd Maste assert(fido_uncompress(&out, &in, sizeof(random_words)) == FIDO_OK);
251*2ccfa855SEd Maste assert(out.len == sizeof(random_words));
252*2ccfa855SEd Maste assert(memcmp(out.ptr, random_words, out.len) == 0);
253*2ccfa855SEd Maste
254*2ccfa855SEd Maste free(in.ptr);
255*2ccfa855SEd Maste free(out.ptr);
256*2ccfa855SEd Maste }
257*2ccfa855SEd Maste
258*2ccfa855SEd Maste int
main(void)259*2ccfa855SEd Maste main(void)
260*2ccfa855SEd Maste {
261*2ccfa855SEd Maste fido_init(0);
262*2ccfa855SEd Maste
263*2ccfa855SEd Maste rfc1950_inflate();
264*2ccfa855SEd Maste rfc1951_inflate();
265*2ccfa855SEd Maste rfc1951_reinflate();
266*2ccfa855SEd Maste
267*2ccfa855SEd Maste exit(0);
268*2ccfa855SEd Maste }
269