summaryrefslogtreecommitdiffstats
path: root/crypto/jpake/jpake.c
diff options
context:
space:
mode:
authorBen Laurie <ben@openssl.org>2010-11-24 13:48:12 +0000
committerBen Laurie <ben@openssl.org>2010-11-24 13:48:12 +0000
commitf9a772b743e01fdb604575025a1735ca4d98e846 (patch)
treea70a8fe5a427a050cb864dda02c6fb9347a05d45 /crypto/jpake/jpake.c
parent0d6f7dbb506379643e4ec227ee9c3ae35ff4aef8 (diff)
J-PAKE was not correctly checking values, which could lead to attacks.
Diffstat (limited to 'crypto/jpake/jpake.c')
-rw-r--r--crypto/jpake/jpake.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/crypto/jpake/jpake.c b/crypto/jpake/jpake.c
index 086d9f47e0..8e4b633ccc 100644
--- a/crypto/jpake/jpake.c
+++ b/crypto/jpake/jpake.c
@@ -282,8 +282,37 @@ int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx)
return 1;
}
+/* g^x is a legal value */
+static int is_legal(const BIGNUM *gx, const JPAKE_CTX *ctx)
+ {
+ BIGNUM *t;
+ int res;
+
+ if(BN_is_negative(gx) || BN_is_zero(gx) || BN_cmp(gx, ctx->p.p) >= 0)
+ return 0;
+
+ t = BN_new();
+ BN_mod_exp(t, gx, ctx->p.q, ctx->p.p, ctx->ctx);
+ res = BN_is_one(t);
+ BN_free(t);
+
+ return res;
+ }
+
int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received)
{
+ if(!is_legal(received->p1.gx, ctx))
+ {
+ JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X3_IS_NOT_LEGAL);
+ return 0;
+ }
+
+ if(!is_legal(received->p2.gx, ctx))
+ {
+ JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X4_IS_NOT_LEGAL);
+ return 0;
+ }
+
/* verify their ZKP(xc) */
if(!verify_zkp(&received->p1, ctx->p.g, ctx))
{