/* Return sign (-1, 0, +1) of a-b. a <=> b --> bnCmpQ(a, b) <=> 0 */ PGPInt32 PGPBigNumCompareQ( PGPBigNumRef bn, PGPUInt16 sm ) { PGPUInt32 result = 0; if ( pgpBigNumIsValid( bn ) ) { result = bnCmpQ( &bn->bn, sm ); } return( result ); }
int32_t ZrtpDH::checkPubKey(uint8_t *pubKeyBytes) const { /* ECC validation (partial), NIST SP800-56A, section 5.6.2.6 */ if (pkType == EC25 || pkType == EC38 || pkType == E414) { dhCtx* tmpCtx = static_cast<dhCtx*>(ctx); EcPoint pub; INIT_EC_POINT(&pub); int32_t len = getPubKeySize() / 2; bnInsertBigBytes(pub.x, pubKeyBytes, 0, len); bnInsertBigBytes(pub.y, pubKeyBytes+len, 0, len); return ecCheckPubKey(&tmpCtx->curve, &pub); } if (pkType == E255) { return 1; } BigNum pubKeyOther; bnBegin(&pubKeyOther); bnInsertBigBytes(&pubKeyOther, pubKeyBytes, 0, getDhSize()); if (pkType == DH2K) { if (bnCmp(&bnP2048MinusOne, &pubKeyOther) == 0) { return 0; } } else if (pkType == DH3K) { if (bnCmp(&bnP3072MinusOne, &pubKeyOther) == 0) { return 0; } } else { return 0; } if (bnCmpQ(&pubKeyOther, 1) == 0) { return 0; } bnEnd(&pubKeyOther); return 1; }