diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/jpake/jpake.c | 29 | 
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/libcrypto/jpake/jpake.c b/src/lib/libcrypto/jpake/jpake.c index 086d9f47e0..8e4b633ccc 100644 --- a/src/lib/libcrypto/jpake/jpake.c +++ b/src/lib/libcrypto/jpake/jpake.c  | |||
| @@ -282,8 +282,37 @@ int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx) | |||
| 282 | return 1; | 282 | return 1; | 
| 283 | } | 283 | } | 
| 284 | 284 | ||
| 285 | /* g^x is a legal value */ | ||
| 286 | static int is_legal(const BIGNUM *gx, const JPAKE_CTX *ctx) | ||
| 287 | { | ||
| 288 | BIGNUM *t; | ||
| 289 | int res; | ||
| 290 | |||
| 291 | if(BN_is_negative(gx) || BN_is_zero(gx) || BN_cmp(gx, ctx->p.p) >= 0) | ||
| 292 | return 0; | ||
| 293 | |||
| 294 | t = BN_new(); | ||
| 295 | BN_mod_exp(t, gx, ctx->p.q, ctx->p.p, ctx->ctx); | ||
| 296 | res = BN_is_one(t); | ||
| 297 | BN_free(t); | ||
| 298 | |||
| 299 | return res; | ||
| 300 | } | ||
| 301 | |||
| 285 | int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received) | 302 | int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received) | 
| 286 | { | 303 | { | 
| 304 | if(!is_legal(received->p1.gx, ctx)) | ||
| 305 | { | ||
| 306 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X3_IS_NOT_LEGAL); | ||
| 307 | return 0; | ||
| 308 | } | ||
| 309 | |||
| 310 | if(!is_legal(received->p2.gx, ctx)) | ||
| 311 | { | ||
| 312 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X4_IS_NOT_LEGAL); | ||
| 313 | return 0; | ||
| 314 | } | ||
| 315 | |||
| 287 | /* verify their ZKP(xc) */ | 316 | /* verify their ZKP(xc) */ | 
| 288 | if(!verify_zkp(&received->p1, ctx->p.g, ctx)) | 317 | if(!verify_zkp(&received->p1, ctx->p.g, ctx)) | 
| 289 | { | 318 | { | 
