176 EVP_MD_CTX *hmac_ctx;
180 uint8_t mip_rk_1[EVP_MAX_MD_SIZE], mip_rk_2[EVP_MAX_MD_SIZE];
181 uint8_t mip_rk[2 * EVP_MAX_MD_SIZE];
182 size_t rk1_len =
sizeof(mip_rk_1), rk2_len =
sizeof(mip_rk_2), rk_len =
sizeof(mip_rk);
187 REDEBUG2(
"No EAP-MSK or EAP-EMSK. Cannot create WiMAX keys");
195 if (
inst->delete_mppe_keys) {
206 memcpy(usage_data,
"miprk@wimaxforum.org", 21);
207 usage_data[21] = 0x02;
208 usage_data[22] = 0x00;
209 usage_data[23] = 0x01;
214 MEM(hmac_ctx = EVP_MD_CTX_new());
215 MEM(hmac_pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, emsk->vp_octets, emsk->vp_length));
216 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
218 EVP_DigestSignUpdate(hmac_ctx, &usage_data[0],
sizeof(usage_data));
219 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
224 EVP_MD_CTX_reset(hmac_ctx);
225 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
227 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mip_rk_1, rk1_len);
228 EVP_DigestSignUpdate(hmac_ctx, &usage_data[0],
sizeof(usage_data));
229 EVP_DigestSignFinal(hmac_ctx, &mip_rk_2[0], &rk2_len);
231 memcpy(mip_rk, mip_rk_1, rk1_len);
232 memcpy(mip_rk + rk1_len, mip_rk_2, rk2_len);
233 rk_len = rk1_len + rk2_len;
238 EVP_MD_CTX_reset(hmac_ctx);
239 EVP_PKEY_free(hmac_pkey);
240 MEM(hmac_pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, mip_rk, rk_len));
241 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha256(), NULL, hmac_pkey);
243 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"SPI CMIP PMIP", 13);
244 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
251 if (mip_spi < 256) mip_spi += 256;
254 REDEBUG2(
"MIP-SPI = %08x", ntohl(mip_spi));
267 RWDEBUG(
"We cannot calculate MN-HA keys");
277 RWDEBUG(
"Not calculating MN-HA keys");
280 if (
vp)
switch (
vp->vp_uint32) {
295 EVP_MD_CTX_reset(hmac_ctx);
296 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
298 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"PMIP4 MN HA", 11);
299 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv4addr, 4);
300 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
301 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
313 vp->vp_uint32 = mip_spi + 1;
330 EVP_MD_CTX_reset(hmac_ctx);
331 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
333 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"CMIP4 MN HA", 11);
334 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv4addr, 4);
335 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
336 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
348 vp->vp_uint32 = mip_spi;
365 EVP_MD_CTX_reset(hmac_ctx);
366 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
368 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"CMIP6 MN HA", 11);
369 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &ip->vp_ipv6addr, 16);
370 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *) &mn_nai->vp_strvalue, mn_nai->vp_length);
371 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
383 vp->vp_uint32 = mip_spi + 2;
396 if (fa_rk && (fa_rk->vp_length <= 1)) {
397 EVP_MD_CTX_reset(hmac_ctx);
398 EVP_DigestSignInit(hmac_ctx, NULL, EVP_sha1(), NULL, hmac_pkey);
400 EVP_DigestSignUpdate(hmac_ctx, (
uint8_t const *)
"FA-RK", 5);
402 EVP_DigestSignFinal(hmac_ctx, &mip_rk_1[0], &rk1_len);
413 vp->vp_uint32 = mip_spi;
423 REDEBUG2(
"Client requested MN-HA key: Should use SPI to look up key from storage");
425 RWDEBUG(
"MN-NAI was not found!");
432 RWDEBUG(
"HA-IP was not found!");
439 if (
vp && (
vp->vp_uint32 == 1)) {
440 REDEBUG2(
"Client requested HA-RK: Should use IP to look it up from storage");
447 EVP_MD_CTX_free(hmac_ctx);
448 EVP_PKEY_free(hmac_pkey);