void handle_dump(queue_t *q, mblk_t *mp) { struct ctrl_args *ctrl_args; struct ctrl_device *ctrlfd; minor_t minor; int sum; unsigned char *buf; if ((mp->b_cont = allocb(MAXPRINTBUF, BPRI_MED)) == NULL) { printf("handle_ctrl: out of message blocks\n"); qreply(q, mp); return; } buf = DB_BASE(mp->b_cont); sum = rpc_dump(buf, buf + MAXPRINTBUF); sum += port_dump(buf + sum, buf + MAXPRINTBUF); sum += kid_dump(buf + sum, buf + MAXPRINTBUF); sum += flip_netdump(buf + sum, buf + MAXPRINTBUF); sum += int_dump(buf + sum, buf + MAXPRINTBUF); sum += adr_dump(buf + sum, buf + MAXPRINTBUF); sum += ff_dump(buf + sum, buf + MAXPRINTBUF); mp->b_cont->b_rptr = DB_BASE(mp->b_cont); mp->b_cont->b_wptr = mp->b_cont->b_rptr + sum; ctrl_args = (struct ctrl_args *) DB_BASE(mp); ctrl_args->ctrl_status = sum; mp->b_rptr = DB_BASE(mp); mp->b_wptr = mp->b_rptr + sizeof(struct ctrl_args); DB_TYPE(mp) = M_PROTO; qreply(q, mp); }
static void calculate_errk(uint8_t *y2, uint8_t *ims, uint8_t *errk_n) { uint8_t z3[SHA256_HASH_DIGEST_SIZE]; MCL_rsa_public_key_RSA2048 pub; MCL_rsa_private_key_RSA2048 priv; uint8_t errk_p[RSA2048_PUBLIC_KEY_SIZE/2]; uint8_t errk_q[RSA2048_PUBLIC_KEY_SIZE/2]; /* Z3 = sha256(Y2 || copy(0x03, 32)) */ sha256_concat(y2, 0x03, 32, z3); /** * ERRK_P[0:31] = sha256(Z3 || copy(0x01, 32)) * ERRK_P[32:63] = sha256(Z3 || copy(0x02, 32)) * ERRK_P[64:95] = sha256(Z3 || copy(0x03, 32)) * ERRK_P[96:127] = sha256(Z3 || copy(0x04, 32)) * ERRK_P[0] |= 0x03 */ sha256_concat(z3, 0x01, 32, &errk_p[0]); sha256_concat(z3, 0x02, 32, &errk_p[32]); sha256_concat(z3, 0x03, 32, &errk_p[64]); sha256_concat(z3, 0x04, 32, &errk_p[96]); errk_p[0] |= ERRK_ALIAS_MOD_BITS; bytes_to_MCL_FF(errk_p, RSA2048_PUBLIC_KEY_SIZE/2, priv.p, MCL_FFLEN1/2); /** * ERRK_Q[0:31] = sha256(Z3 || copy(0x05, 32)) * ERRK_Q[32:63] = sha256(Z3 || copy(0x06, 32)) * ERRK_Q[64:95] = sha256(Z3 || copy(0x07, 32)) * ERRK_Q[96:127] = sha256(Z3 || copy(0x08, 32)) * ERRK_Q[0] |= 0x03 */ sha256_concat(z3, 0x05, 32, &errk_q[0]); sha256_concat(z3, 0x06, 32, &errk_q[32]); sha256_concat(z3, 0x07, 32, &errk_q[64]); sha256_concat(z3, 0x08, 32, &errk_q[96]); errk_q[0] |= ERRK_ALIAS_MOD_BITS; bytes_to_MCL_FF(errk_q, RSA2048_PUBLIC_KEY_SIZE/2, priv.q, MCL_FFLEN1/2); /* ERRK_P += 4 * IMS[34:32] / 4096 */ /* ERRK_Q += 4 * IMS[34:32] % 4096 */ uint32_t alias_ims = (*((uint32_t *)&ims[32]) & 0x00FFFFFF); MCL_FF_inc_C448(priv.p, (alias_ims >> 12) << ERRK_ALIAS_MOD_SHIFT, MCL_FFLEN1/2); MCL_FF_inc_C448(priv.q, (alias_ims & 0xFFF) << ERRK_ALIAS_MOD_SHIFT, MCL_FFLEN1/2); #if DBG_SECRET_KEY_MSG ff_dump(priv.p, MCL_FFLEN1/2, "p "); ff_dump(priv.q, MCL_FFLEN1/2, "q "); #endif /* ERPK_MOD = ERRK_Q * ERRK_P */ MCL_FF_mul_C448(pub.n, priv.p, priv.q, MCL_FFLEN1/2); #if DBG_SECRET_KEY_MSG ff_dump(pub.n, MCL_FFLEN1, "n "); #endif MCL_FF_to_bytes(pub.n, MCL_FFLEN1, errk_n, RSA2048_PUBLIC_KEY_SIZE); /* ERPK_E = 65537 */ pub.e = 65537; /* TBD: do we even need the private key on the bridge side? */ /* ERRK_D = RSA_secret(ERRK_P, ERRK_Q, ERPK_E) */ }