169 EVP_MD_CTX *hmac_ctx;
173 uint8_t mip_rk_1[EVP_MAX_MD_SIZE], mip_rk_2[EVP_MAX_MD_SIZE];
174 uint8_t mip_rk[2 * EVP_MAX_MD_SIZE];
175 size_t rk1_len =
sizeof(mip_rk_1), rk2_len =
sizeof(mip_rk_2), rk_len =
sizeof(mip_rk);
180 REDEBUG2(
"No EAP-MSK or EAP-EMSK. Cannot create WiMAX keys");
188 if (
inst->delete_mppe_keys) {
199 memcpy(usage_data,
"miprk@wimaxforum.org", 21);
200 usage_data[21] = 0x02;
201 usage_data[22] = 0x00;
202 usage_data[23] = 0x01;
207 MEM(hmac_ctx = EVP_MD_CTX_new());
208 MEM(hmac_pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, emsk->vp_octets, emsk->vp_length));
209 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
211 EVP_DigestSignUpdate(hmac_ctx, &usage_data[0],
sizeof(usage_data));
212 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
217 EVP_MD_CTX_reset(hmac_ctx);
218 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
220 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mip_rk_1, rk1_len);
221 EVP_DigestSignUpdate(hmac_ctx, &usage_data[0],
sizeof(usage_data));
222 EVP_DigestSignFinal(hmac_ctx, &mip_rk_2[0], &rk2_len);
224 memcpy(mip_rk, mip_rk_1, rk1_len);
225 memcpy(mip_rk + rk1_len, mip_rk_2, rk2_len);
226 rk_len = rk1_len + rk2_len;
231 EVP_MD_CTX_reset(hmac_ctx);
232 EVP_PKEY_free(hmac_pkey);
233 MEM(hmac_pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, mip_rk, rk_len));
234 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
236 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"SPI CMIP PMIP", 12);
237 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
244 if (mip_spi < 256) mip_spi += 256;
247 REDEBUG2(
"MIP-SPI = %08x", ntohl(mip_spi));
260 RWDEBUG(
"We cannot calculate MN-HA keys");
270 RWDEBUG(
"Not calculating MN-HA keys");
273 if (
vp)
switch (
vp->vp_uint32) {
288 EVP_MD_CTX_reset(hmac_ctx);
289 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
291 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"PMIP4 MN HA", 11);
292 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv4addr, 4);
293 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
294 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
306 vp->vp_uint32 = mip_spi + 1;
323 EVP_MD_CTX_reset(hmac_ctx);
324 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
326 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"CMIP4 MN HA", 11);
327 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv4addr, 4);
328 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
329 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
341 vp->vp_uint32 = mip_spi;
358 EVP_MD_CTX_reset(hmac_ctx);
359 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
361 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"CMIP6 MN HA", 11);
362 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv6addr, 16);
363 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
364 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
376 vp->vp_uint32 = mip_spi + 2;
389 if (fa_rk && (fa_rk->vp_length <= 1)) {
390 EVP_MD_CTX_reset(hmac_ctx);
391 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
393 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"FA-RK", 5);
395 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
406 vp->vp_uint32 = mip_spi;
416 REDEBUG2(
"Client requested MN-HA key: Should use SPI to look up key from storage");
418 RWDEBUG(
"MN-NAI was not found!");
425 RWDEBUG(
"HA-IP was not found!");
432 if (
vp && (
vp->vp_uint32 == 1)) {
433 REDEBUG2(
"Client requested HA-RK: Should use IP to look it up from storage");
440 EVP_MD_CTX_free(hmac_ctx);
441 EVP_PKEY_free(hmac_pkey);