Lines Matching refs:jwe
26 #include "private-lib-jose-jwe.h"
31 * - jwe->jws.map LJWE_JOSE contains the ASCII JOSE header
32 * - jwe->jws.map LJWE_EKEY contains cek of enc_alg hmac length
33 * - jwe->jws.map LJWE_CTXT contains the plaintext
37 * - jwe->jws.map LJWE_ATAG contains the tag
38 * - jwe->jws.map LJWE_IV contains the new random IV that was used
39 * - jwe->jws.map LJWE_EKEY contains the encrypted CEK
40 * - jwe->jws.map LJWE_CTXT contains the ciphertext
46 lws_jwe_encrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe,
49 int n, hlen = (int)lws_genhmac_size(jwe->jose.enc_alg->hmac_type),
54 if (jwe->jws.jwk->kty != LWS_GENCRYPTO_KTY_RSA) {
55 lwsl_err("%s: unexpected kty %d\n", __func__, jwe->jws.jwk->kty);
66 if (lws_jws_encode_b64_element(&jwe->jws.map_b64, LJWE_JOSE,
68 jwe->jws.map.buf[LJWE_JOSE],
69 jwe->jws.map.len[LJWE_JOSE]))
72 if (lws_jws_alloc_element(&jwe->jws.map, LJWE_ATAG, temp + (ot - *temp_len),
76 if (lws_jws_alloc_element(&jwe->jws.map, LJWE_IV, temp + (ot - *temp_len),
84 if (lws_jws_dup_element(&jwe->jws.map, LJWE_EKEY, temp + (ot - *temp_len),
85 temp_len, jwe->jws.map.buf[LJWE_EKEY],
86 jwe->jws.map.len[LJWE_EKEY],
87 jwe->jws.jwk->e[LWS_GENCRYPTO_RSA_KEYEL_N].len))
92 n = lws_jwe_encrypt_cbc_hs(jwe, (uint8_t *)jwe->jws.map.buf[LJWE_EKEY],
93 (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE],
94 (int)jwe->jws.map_b64.len[LJWE_JOSE]);
100 if (lws_genrsa_create(&rsactx, jwe->jws.jwk->e, jwe->jws.context,
101 !strcmp(jwe->jose.alg->alg, "RSA-OAEP") ?
112 memcpy(ekey, jwe->jws.map.buf[LJWE_EKEY], (unsigned int)hlen);
115 (uint8_t *)jwe->jws.map.buf[LJWE_EKEY]);
122 jwe->jws.map.len[LJWE_EKEY] = (unsigned int)n; /* update to encrypted EKEY size */
133 lws_jwe_auth_and_decrypt_rsa_aes_cbc_hs(struct lws_jwe *jwe)
139 if (jwe->jws.jwk->kty != LWS_GENCRYPTO_KTY_RSA) {
140 lwsl_err("%s: unexpected kty %d\n", __func__, jwe->jws.jwk->kty);
145 if (jwe->jws.map.len[LJWE_EKEY] < 40) {
147 jwe->jws.map.len[LJWE_EKEY]);
154 if (lws_genrsa_create(&rsactx, jwe->jws.jwk->e, jwe->jws.context,
155 !strcmp(jwe->jose.alg->alg, "RSA-OAEP") ?
164 (uint8_t *)jwe->jws.map.buf[LJWE_EKEY],
165 jwe->jws.map.len[LJWE_EKEY], enc_cek,
173 n = lws_jwe_auth_and_decrypt_cbc_hs(jwe, enc_cek,
174 (uint8_t *)jwe->jws.map_b64.buf[LJWE_JOSE],
175 (int)jwe->jws.map_b64.len[LJWE_JOSE]);
186 n = jwe->jws.map.buf[LJWE_CTXT][jwe->jws.map.len[LJWE_CTXT] - 1];
189 (int)jwe->jws.map.len[LJWE_CTXT]);
192 jwe->jws.map.len[LJWE_CTXT] -= n;
195 return (int)jwe->jws.map.len[LJWE_CTXT];