… | |
… | |
39 | |
39 | |
40 | #include "crypto.h" |
40 | #include "crypto.h" |
41 | #include "util.h" |
41 | #include "util.h" |
42 | #include "hkdf.h" |
42 | #include "hkdf.h" |
43 | |
43 | |
|
|
44 | hkdf::hkdf (const void *salt, int len, const EVP_MD *xtr_hash) |
|
|
45 | : salt (salt), salt_len (len) |
|
|
46 | { |
|
|
47 | ctx.init (salt, salt_len, xtr_hash); |
|
|
48 | } |
|
|
49 | |
44 | void |
50 | void |
45 | hkdf::extract (const void *ikm, int len) |
51 | hkdf::extract (const void *ikm, int len) |
46 | { |
52 | { |
47 | ctx.add (ikm, len); |
53 | ctx.add (ikm, len); |
48 | } |
54 | } |
49 | |
55 | |
50 | void |
56 | void |
51 | hkdf::extract_done (const EVP_MD *prf_hash) |
57 | hkdf::extract_done (const EVP_MD *prf_hash) |
52 | { |
58 | { |
53 | ctx.digest (prk); |
59 | ctx.digest (prk); |
54 | ctx.init (0, 0, prf_hash); |
60 | ctx.init (salt, salt_len, prf_hash); |
55 | } |
61 | } |
56 | |
62 | |
57 | void |
63 | void |
58 | hkdf::expand (void *okm, int len, const void *info, int infolen) |
64 | hkdf::expand (void *okm, int len, const void *info, int infolen) |
59 | { |
65 | { |
… | |
… | |
99 | u8 s[256]; |
105 | u8 s[256]; |
100 | |
106 | |
101 | unhex (const char *hs) |
107 | unhex (const char *hs) |
102 | { |
108 | { |
103 | l = 0; |
109 | l = 0; |
104 | p = 0; |
110 | p = s; |
105 | |
111 | |
106 | if (!hs) |
112 | if (!hs) |
107 | return; |
113 | return; |
108 | |
|
|
109 | p = s; |
|
|
110 | |
114 | |
111 | while (*hs) |
115 | while (*hs) |
112 | { |
116 | { |
113 | int d1 = *hs >= '0' && *hs <= '9' ? *hs - '0' : *hs - 'a' + 10; ++hs; |
117 | int d1 = *hs >= '0' && *hs <= '9' ? *hs - '0' : *hs - 'a' + 10; ++hs; |
114 | int d2 = *hs >= '0' && *hs <= '9' ? *hs - '0' : *hs - 'a' + 10; ++hs; |
118 | int d2 = *hs >= '0' && *hs <= '9' ? *hs - '0' : *hs - 'a' + 10; ++hs; |