Lines Matching refs:jwe
137 lws_jwe_json_parse(struct lws_jwe *jwe, const uint8_t *buf, int len, in lws_jwe_json_parse() argument
144 args.jws = &jwe->jws; in lws_jwe_json_parse()
162 lws_jwe_init(struct lws_jwe *jwe, struct lws_context *context) in lws_jwe_init() argument
164 lws_jose_init(&jwe->jose); in lws_jwe_init()
165 lws_jws_init(&jwe->jws, &jwe->jwk, context); in lws_jwe_init()
166 memset(&jwe->jwk, 0, sizeof(jwe->jwk)); in lws_jwe_init()
167 jwe->recip = 0; in lws_jwe_init()
168 jwe->cek_valid = 0; in lws_jwe_init()
172 lws_jwe_destroy(struct lws_jwe *jwe) in lws_jwe_destroy() argument
174 lws_jws_destroy(&jwe->jws); in lws_jwe_destroy()
175 lws_jose_destroy(&jwe->jose); in lws_jwe_destroy()
176 lws_jwk_destroy(&jwe->jwk); in lws_jwe_destroy()
178 lws_explicit_bzero(jwe->cek, sizeof(jwe->cek)); in lws_jwe_destroy()
179 jwe->cek_valid = 0; in lws_jwe_destroy()
209 lws_jwa_concat_kdf(struct lws_jwe *jwe, int direct, uint8_t *out, in lws_jwa_concat_kdf() argument
217 if (!jwe->jose.enc_alg || !jwe->jose.alg) in lws_jwa_concat_kdf()
238 aid = direct ? jwe->jose.enc_alg->alg : jwe->jose.alg->alg; in lws_jwa_concat_kdf()
271 while (ctr <= (uint32_t)((jwe->jose.enc_alg->keybits_fixed + (hlen - 1)) / hlen)) { in lws_jwa_concat_kdf()
290 be32(jwe->jose.e[LJJHI_APU].len, &t), 4) || in lws_jwa_concat_kdf()
291 lws_genhash_update(&hash_ctx, jwe->jose.e[LJJHI_APU].buf, in lws_jwa_concat_kdf()
292 jwe->jose.e[LJJHI_APU].len) || in lws_jwa_concat_kdf()
294 be32(jwe->jose.e[LJJHI_APV].len, &t), 4) || in lws_jwa_concat_kdf()
295 lws_genhash_update(&hash_ctx, jwe->jose.e[LJJHI_APV].buf, in lws_jwa_concat_kdf()
296 jwe->jose.e[LJJHI_APV].len) || in lws_jwa_concat_kdf()
298 be32(jwe->jose.enc_alg->keybits_fixed, &t), in lws_jwa_concat_kdf()
323 lws_jwe_auth_and_decrypt(struct lws_jwe *jwe, char *temp, int *temp_len) in lws_jwe_auth_and_decrypt() argument
328 if (lws_jwe_parse_jose(&jwe->jose, jwe->jws.map.buf[LJWS_JOSE], in lws_jwe_auth_and_decrypt()
329 (int)jwe->jws.map.len[LJWS_JOSE], in lws_jwe_auth_and_decrypt()
331 lws_strnncpy(dotstar, jwe->jws.map.buf[LJWS_JOSE], in lws_jwe_auth_and_decrypt()
332 jwe->jws.map.len[LJWS_JOSE], sizeof(dotstar)); in lws_jwe_auth_and_decrypt()
337 if (!jwe->jose.alg) { in lws_jwe_auth_and_decrypt()
338 lws_strnncpy(dotstar, jwe->jws.map.buf[LJWS_JOSE], in lws_jwe_auth_and_decrypt()
339 jwe->jws.map.len[LJWS_JOSE], sizeof(dotstar)); in lws_jwe_auth_and_decrypt()
345 valid_aescbc_hmac = jwe->jose.enc_alg && in lws_jwe_auth_and_decrypt()
346 jwe->jose.enc_alg->algtype_crypto == LWS_JOSE_ENCTYPE_AES_CBC && in lws_jwe_auth_and_decrypt()
347 (jwe->jose.enc_alg->hmac_type == LWS_GENHMAC_TYPE_SHA256 || in lws_jwe_auth_and_decrypt()
348 jwe->jose.enc_alg->hmac_type == LWS_GENHMAC_TYPE_SHA384 || in lws_jwe_auth_and_decrypt()
349 jwe->jose.enc_alg->hmac_type == LWS_GENHMAC_TYPE_SHA512); in lws_jwe_auth_and_decrypt()
351 valid_aesgcm = jwe->jose.enc_alg && in lws_jwe_auth_and_decrypt()
352 jwe->jose.enc_alg->algtype_crypto == LWS_JOSE_ENCTYPE_AES_GCM; in lws_jwe_auth_and_decrypt()
354 if ((jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_RSASSA_PKCS1_1_5 || in lws_jwe_auth_and_decrypt()
355 jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_RSASSA_PKCS1_OAEP)) { in lws_jwe_auth_and_decrypt()
358 return lws_jwe_auth_and_decrypt_rsa_aes_cbc_hs(jwe); in lws_jwe_auth_and_decrypt()
361 return lws_jwe_auth_and_decrypt_rsa_aes_gcm(jwe); in lws_jwe_auth_and_decrypt()
366 if (jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_AES_ECB && in lws_jwe_auth_and_decrypt()
368 return lws_jwe_auth_and_decrypt_aeskw_cbc_hs(jwe); in lws_jwe_auth_and_decrypt()
372 if (jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_ECDHES && in lws_jwe_auth_and_decrypt()
374 return lws_jwe_auth_and_decrypt_ecdh_cbc_hs(jwe, in lws_jwe_auth_and_decrypt()
378 jwe->jose.alg->alg, jwe->jose.enc_alg ? in lws_jwe_auth_and_decrypt()
379 jwe->jose.enc_alg->alg : "NULL"); in lws_jwe_auth_and_decrypt()
384 lws_jwe_encrypt(struct lws_jwe *jwe, char *temp, int *temp_len) in lws_jwe_encrypt() argument
388 if (jwe->jose.recipients >= (int)LWS_ARRAY_SIZE(jwe->jose.recipient)) { in lws_jwe_encrypt()
394 valid_aesgcm = jwe->jose.enc_alg && in lws_jwe_encrypt()
395 jwe->jose.enc_alg->algtype_crypto == LWS_JOSE_ENCTYPE_AES_GCM; in lws_jwe_encrypt()
397 if (lws_jwe_parse_jose(&jwe->jose, jwe->jws.map.buf[LJWS_JOSE], in lws_jwe_encrypt()
398 (int)jwe->jws.map.len[LJWS_JOSE], temp, temp_len) < 0) { in lws_jwe_encrypt()
405 valid_aescbc_hmac = jwe->jose.enc_alg && in lws_jwe_encrypt()
406 jwe->jose.enc_alg->algtype_crypto == LWS_JOSE_ENCTYPE_AES_CBC && in lws_jwe_encrypt()
407 (jwe->jose.enc_alg->hmac_type == LWS_GENHMAC_TYPE_SHA256 || in lws_jwe_encrypt()
408 jwe->jose.enc_alg->hmac_type == LWS_GENHMAC_TYPE_SHA384 || in lws_jwe_encrypt()
409 jwe->jose.enc_alg->hmac_type == LWS_GENHMAC_TYPE_SHA512); in lws_jwe_encrypt()
411 if ((jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_RSASSA_PKCS1_1_5 || in lws_jwe_encrypt()
412 jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_RSASSA_PKCS1_OAEP)) { in lws_jwe_encrypt()
415 ret = lws_jwe_encrypt_rsa_aes_cbc_hs(jwe, temp, temp_len); in lws_jwe_encrypt()
420 ret = lws_jwe_encrypt_rsa_aes_gcm(jwe, temp, temp_len); in lws_jwe_encrypt()
427 if (jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_AES_ECB && in lws_jwe_encrypt()
429 ret = lws_jwe_encrypt_aeskw_cbc_hs(jwe, temp, temp_len); in lws_jwe_encrypt()
435 if (jwe->jose.alg->algtype_signing == LWS_JOSE_ENCTYPE_ECDHES && in lws_jwe_encrypt()
437 ret = lws_jwe_encrypt_ecdh_cbc_hs(jwe, temp, temp_len); in lws_jwe_encrypt()
442 jwe->jose.alg->alg, jwe->jose.enc_alg ? in lws_jwe_encrypt()
443 jwe->jose.enc_alg->alg : "NULL"); in lws_jwe_encrypt()
447 memset(&jwe->jose.recipient[jwe->jose.recipients], 0, in lws_jwe_encrypt()
448 sizeof(jwe->jose.recipient[0])); in lws_jwe_encrypt()
450 jwe->jose.recipients++; in lws_jwe_encrypt()
478 lws_jwe_render_compact(struct lws_jwe *jwe, char *out, size_t out_len) in lws_jwe_render_compact() argument
483 if (jwe->jose.recipients > 1) { in lws_jwe_render_compact()
486 jwe->jose.recipients); in lws_jwe_render_compact()
491 n = lws_jws_base64_enc(jwe->jws.map.buf[LJWS_JOSE], in lws_jwe_render_compact()
492 jwe->jws.map.len[LJWS_JOSE], out, out_len); in lws_jwe_render_compact()
502 n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_EKEY], in lws_jwe_render_compact()
503 jwe->jws.map.len[LJWE_EKEY], out, out_len); in lws_jwe_render_compact()
512 n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_IV], in lws_jwe_render_compact()
513 jwe->jws.map.len[LJWE_IV], out, out_len); in lws_jwe_render_compact()
523 n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_CTXT], in lws_jwe_render_compact()
524 jwe->jws.map.len[LJWE_CTXT], out, out_len); in lws_jwe_render_compact()
533 n = lws_jws_base64_enc(jwe->jws.map.buf[LJWE_ATAG], in lws_jwe_render_compact()
534 jwe->jws.map.len[LJWE_ATAG], out, out_len); in lws_jwe_render_compact()
548 lws_jwe_create_packet(struct lws_jwe *jwe, const char *payload, size_t len, in lws_jwe_create_packet() argument
556 lws_jws_init(&jws, &jwe->jwk, context); in lws_jwe_create_packet()
578 if (!jwe->jose.alg || !jwe->jose.alg->alg) in lws_jwe_create_packet()
582 jwe->jose.alg->alg); in lws_jwe_create_packet()
584 n = lws_jwk_export(&jwe->jwk, 0, p, &m); in lws_jwe_create_packet()
636 n = lws_jws_sign_from_b64(&jwe->jose, &jws, p1, lws_ptr_diff_size_t(end1, p1)); in lws_jwe_create_packet()
722 lws_jwe_render_flattened(struct lws_jwe *jwe, char *out, size_t out_len) in lws_jwe_render_flattened() argument
727 jlen = lws_jose_render(&jwe->jose, jwe->jws.jwk, buf, sizeof(buf)); in lws_jwe_render_flattened()
747 jwe->jose.alg->alg, jwe->jose.enc_alg->alg); in lws_jwe_render_flattened()
750 jwe->jws.map_b64.buf[LJWS_JOSE] = p1; in lws_jwe_render_flattened()
756 jwe->jws.map_b64.len[LJWS_JOSE] = (unsigned int)n; in lws_jwe_render_flattened()
766 if (jwe->jws.map.buf[protected_idx[m]]) { in lws_jwe_render_flattened()
770 n = lws_jws_base64_enc(jwe->jws.map.buf[protected_idx[m]], in lws_jwe_render_flattened()
771 jwe->jws.map.len[protected_idx[m]], in lws_jwe_render_flattened()
788 lws_jws_destroy(&jwe->jws); in lws_jwe_render_flattened()