Lines Matching refs:ctx

36 lws_genhash_init(struct lws_genhash_ctx *ctx, enum lws_genhash_types type)
38 ctx->type = (uint8_t)type;
39 ctx->mdctx = EVP_MD_CTX_create();
40 if (!ctx->mdctx)
43 switch (ctx->type) {
45 ctx->evp_type = EVP_md5();
48 ctx->evp_type = EVP_sha1();
51 ctx->evp_type = EVP_sha256();
54 ctx->evp_type = EVP_sha384();
57 ctx->evp_type = EVP_sha512();
63 if (EVP_DigestInit_ex(ctx->mdctx, ctx->evp_type, NULL) != 1) {
64 EVP_MD_CTX_destroy(ctx->mdctx);
73 lws_genhash_update(struct lws_genhash_ctx *ctx, const void *in, size_t len)
78 return EVP_DigestUpdate(ctx->mdctx, in, len) != 1;
82 lws_genhash_destroy(struct lws_genhash_ctx *ctx, void *result)
87 if (!ctx->mdctx)
91 ret = EVP_DigestFinal_ex(ctx->mdctx, result, &len) != 1;
95 EVP_MD_CTX_destroy(ctx->mdctx);
96 ctx->mdctx = NULL;
104 lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type,
107 ctx->ctx = EVP_MD_CTX_create();
108 if (!ctx->ctx)
111 ctx->evp_type = 0;
112 ctx->type = (uint8_t)type;
116 ctx->evp_type = EVP_sha256();
119 ctx->evp_type = EVP_sha384();
122 ctx->evp_type = EVP_sha512();
129 ctx->key = EVP_PKEY_new_raw_private_key(EVP_PKEY_HMAC, NULL, key, key_len);
130 if (!ctx->key)
133 if (EVP_DigestSignInit(ctx->ctx, NULL, ctx->evp_type, NULL, ctx->key) != 1)
139 EVP_PKEY_free(ctx->key);
141 EVP_MD_CTX_free(ctx->ctx);
147 lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len)
150 if (EVP_DigestSignUpdate(ctx->ctx, in, len) != 1)
157 lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result)
159 size_t size = (size_t)lws_genhmac_size(ctx->type);
162 n = EVP_DigestSignFinal(ctx->ctx, result, &size);
163 EVP_MD_CTX_free(ctx->ctx);
164 EVP_PKEY_free(ctx->key);
175 lws_genhmac_init(struct lws_genhmac_ctx *ctx, enum lws_genhmac_types type,
179 ctx->ctx = HMAC_CTX_new();
180 if (!ctx->ctx)
183 HMAC_CTX_init(&ctx->ctx);
186 ctx->evp_type = 0;
187 ctx->type = (uint8_t)type;
191 ctx->evp_type = EVP_sha256();
194 ctx->evp_type = EVP_sha384();
197 ctx->evp_type = EVP_sha512();
205 if (HMAC_Init_ex(ctx->ctx, key, (int)key_len, ctx->evp_type, NULL) != 1)
207 if (HMAC_Init_ex(&ctx->ctx, key, (int)key_len, ctx->evp_type, NULL) != 1)
215 HMAC_CTX_free(ctx->ctx);
222 lws_genhmac_update(struct lws_genhmac_ctx *ctx, const void *in, size_t len)
226 if (HMAC_Update(ctx->ctx, in, len) != 1)
228 if (HMAC_Update(ctx->ctx, in, (int)len) != 1)
231 if (HMAC_Update(&ctx->ctx, in, len) != 1)
239 lws_genhmac_destroy(struct lws_genhmac_ctx *ctx, void *result)
241 unsigned int size = (unsigned int)lws_genhmac_size(ctx->type);
243 int n = HMAC_Final(ctx->ctx, result, &size);
245 HMAC_CTX_free(ctx->ctx);
247 int n = HMAC_Final(&ctx->ctx, result, &size);