Lines Matching refs:ctx

45 rsa_pkey_wrap(struct lws_genrsa_ctx *ctx, RSA *rsa)
64 ctx->ctx = EVP_PKEY_CTX_new(pkey, NULL);
67 if (!ctx->ctx)
80 lws_genrsa_create(struct lws_genrsa_ctx *ctx,
87 memset(ctx, 0, sizeof(*ctx));
88 ctx->context = context;
89 ctx->mode = mode;
97 ctx->bn[n] = BN_bin2bn(el[n].buf, (int)el[n].len, NULL);
98 if (!ctx->bn[n]) {
109 ctx->rsa = RSA_new();
110 if (!ctx->rsa) {
116 if (RSA_set0_key(ctx->rsa, ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_N],
117 ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_E],
118 ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_D]) != 1) {
122 RSA_set0_factors(ctx->rsa, ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_P],
123 ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_Q]);
125 ctx->rsa->e = ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_E];
126 ctx->rsa->n = ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_N];
127 ctx->rsa->d = ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_D];
128 ctx->rsa->p = ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_P];
129 ctx->rsa->q = ctx->bn[LWS_GENCRYPTO_RSA_KEYEL_Q];
132 if (!rsa_pkey_wrap(ctx, ctx->rsa))
137 if (ctx->bn[n]) {
138 BN_clear_free(ctx->bn[n]);
139 ctx->bn[n] = NULL;
142 if (ctx->rsa) {
143 RSA_free(ctx->rsa);
144 ctx->rsa = NULL;
151 lws_genrsa_new_keypair(struct lws_context *context, struct lws_genrsa_ctx *ctx,
158 memset(ctx, 0, sizeof(*ctx));
159 ctx->context = context;
160 ctx->mode = mode;
162 ctx->rsa = RSA_new();
163 if (!ctx->rsa) {
176 n = RSA_generate_key_ex(ctx->rsa, bits, bn, NULL);
185 RSA_get0_key(ctx->rsa, &mpi[LWS_GENCRYPTO_RSA_KEYEL_N],
187 RSA_get0_factors(ctx->rsa, &mpi[LWS_GENCRYPTO_RSA_KEYEL_P],
191 BIGNUM *mpi[5] = { ctx->rsa->e, ctx->rsa->n, ctx->rsa->d,
192 ctx->rsa->p, ctx->rsa->q, };
205 if (!rsa_pkey_wrap(ctx, ctx->rsa))
213 RSA_free(ctx->rsa);
214 ctx->rsa = NULL;
225 lws_genrsa_public_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
228 int n = RSA_public_encrypt((int)in_len, in, out, ctx->rsa,
229 mode_map_crypt[ctx->mode]);
240 lws_genrsa_private_encrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
243 int n = RSA_private_encrypt((int)in_len, in, out, ctx->rsa,
244 mode_map_crypt[ctx->mode]);
255 lws_genrsa_public_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
258 int n = RSA_public_decrypt((int)in_len, in, out, ctx->rsa,
259 mode_map_crypt[ctx->mode]);
269 lws_genrsa_private_decrypt(struct lws_genrsa_ctx *ctx, const uint8_t *in,
272 int n = RSA_private_decrypt((int)in_len, in, out, ctx->rsa,
273 mode_map_crypt[ctx->mode]);
284 lws_genrsa_hash_sig_verify(struct lws_genrsa_ctx *ctx, const uint8_t *in,
295 switch(ctx->mode) {
298 (unsigned int)sig_len, ctx->rsa);
306 n = RSA_verify_pss_mgf1(ctx->rsa, in, h, md, NULL, -1,
309 n = RSA_verify_PKCS1_PSS(ctx->rsa, in, md, (uint8_t *)sig,
328 lws_genrsa_hash_sign(struct lws_genrsa_ctx *ctx, const uint8_t *in,
341 switch(ctx->mode) {
343 if (RSA_sign(n, in, (unsigned int)h, sig, &used, ctx->rsa) != 1) {
356 if (EVP_PKEY_CTX_set_rsa_padding(ctx->ctx,
357 mode_map_sig[ctx->mode]) != 1) {
369 ctx->ctx->pkey)) {
371 EVP_PKEY_CTX_get0_pkey(ctx->ctx))) {
405 lws_genrsa_destroy(struct lws_genrsa_ctx *ctx)
407 if (!ctx->ctx)
410 EVP_PKEY_CTX_free(ctx->ctx);
411 ctx->ctx = NULL;
412 ctx->rsa = NULL;