177 EVP_MD_CTX *hmac_ctx;
181 uint8_t mip_rk_1[EVP_MAX_MD_SIZE], mip_rk_2[EVP_MAX_MD_SIZE];
182 uint8_t mip_rk[2 * EVP_MAX_MD_SIZE];
183 size_t rk1_len =
sizeof(mip_rk_1), rk2_len =
sizeof(mip_rk_2), rk_len =
sizeof(mip_rk);
188 REDEBUG2(
"No EAP-MSK or EAP-EMSK. Cannot create WiMAX keys");
196 if (
inst->delete_mppe_keys) {
207 memcpy(usage_data,
"miprk@wimaxforum.org", 21);
208 usage_data[21] = 0x02;
209 usage_data[22] = 0x00;
210 usage_data[23] = 0x01;
215 MEM(hmac_ctx = EVP_MD_CTX_new());
216 MEM(hmac_pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, emsk->vp_octets, emsk->vp_length));
217 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
219 EVP_DigestSignUpdate(hmac_ctx, &usage_data[0],
sizeof(usage_data));
220 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
225 EVP_MD_CTX_reset(hmac_ctx);
226 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
228 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mip_rk_1, rk1_len);
229 EVP_DigestSignUpdate(hmac_ctx, &usage_data[0],
sizeof(usage_data));
230 EVP_DigestSignFinal(hmac_ctx, &mip_rk_2[0], &rk2_len);
232 memcpy(mip_rk, mip_rk_1, rk1_len);
233 memcpy(mip_rk + rk1_len, mip_rk_2, rk2_len);
234 rk_len = rk1_len + rk2_len;
239 EVP_MD_CTX_reset(hmac_ctx);
240 EVP_PKEY_free(hmac_pkey);
241 MEM(hmac_pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, mip_rk, rk_len));
242 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
244 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"SPI CMIP PMIP", 12);
245 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
252 if (mip_spi < 256) mip_spi += 256;
255 REDEBUG2(
"MIP-SPI = %08x", ntohl(mip_spi));
268 RWDEBUG(
"We cannot calculate MN-HA keys");
278 RWDEBUG(
"Not calculating MN-HA keys");
281 if (
vp)
switch (
vp->vp_uint32) {
296 EVP_MD_CTX_reset(hmac_ctx);
297 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
299 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"PMIP4 MN HA", 11);
300 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv4addr, 4);
301 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
302 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
314 vp->vp_uint32 = mip_spi + 1;
331 EVP_MD_CTX_reset(hmac_ctx);
332 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
334 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"CMIP4 MN HA", 11);
335 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv4addr, 4);
336 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
337 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
349 vp->vp_uint32 = mip_spi;
366 EVP_MD_CTX_reset(hmac_ctx);
367 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
369 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"CMIP6 MN HA", 11);
370 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv6addr, 16);
371 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
372 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
384 vp->vp_uint32 = mip_spi + 2;
397 if (fa_rk && (fa_rk->vp_length <= 1)) {
398 EVP_MD_CTX_reset(hmac_ctx);
399 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
401 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"FA-RK", 5);
403 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
414 vp->vp_uint32 = mip_spi;
424 REDEBUG2(
"Client requested MN-HA key: Should use SPI to look up key from storage");
426 RWDEBUG(
"MN-NAI was not found!");
433 RWDEBUG(
"HA-IP was not found!");
440 if (
vp && (
vp->vp_uint32 == 1)) {
441 REDEBUG2(
"Client requested HA-RK: Should use IP to look it up from storage");
448 EVP_MD_CTX_free(hmac_ctx);
449 EVP_PKEY_free(hmac_pkey);