Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/field_impl.h
/*********************************************************************** | /*********************************************************************** | ||||
* Copyright (c) 2013, 2014 Pieter Wuille * | * Copyright (c) 2013, 2014 Pieter Wuille * | ||||
* Distributed under the MIT software license, see the accompanying * | * Distributed under the MIT software license, see the accompanying * | ||||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.* | * file COPYING or https://www.opensource.org/licenses/mit-license.php.* | ||||
***********************************************************************/ | ***********************************************************************/ | ||||
#ifndef SECP256K1_FIELD_IMPL_H | #ifndef SECP256K1_FIELD_IMPL_H | ||||
#define SECP256K1_FIELD_IMPL_H | #define SECP256K1_FIELD_IMPL_H | ||||
#if defined HAVE_CONFIG_H | #if defined HAVE_CONFIG_H | ||||
#include "libsecp256k1-config.h" | #include "libsecp256k1-config.h" | ||||
#endif | #endif | ||||
#include "util.h" | #include "util.h" | ||||
#include "num.h" | |||||
#if defined(SECP256K1_WIDEMUL_INT128) | #if defined(SECP256K1_WIDEMUL_INT128) | ||||
#include "field_5x52_impl.h" | #include "field_5x52_impl.h" | ||||
#elif defined(SECP256K1_WIDEMUL_INT64) | #elif defined(SECP256K1_WIDEMUL_INT64) | ||||
#include "field_10x26_impl.h" | #include "field_10x26_impl.h" | ||||
#else | #else | ||||
#error "Please select wide multiplication implementation" | #error "Please select wide multiplication implementation" | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | static int secp256k1_fe_sqrt(secp256k1_fe *r, const secp256k1_fe *a) { | ||||
/* Check that a square root was actually calculated */ | /* Check that a square root was actually calculated */ | ||||
secp256k1_fe_sqr(&t1, r); | secp256k1_fe_sqr(&t1, r); | ||||
return secp256k1_fe_equal(&t1, a); | return secp256k1_fe_equal(&t1, a); | ||||
} | } | ||||
static int secp256k1_fe_is_quad_var(const secp256k1_fe *a) { | static int secp256k1_fe_is_quad_var(const secp256k1_fe *a) { | ||||
#ifndef USE_NUM_NONE | |||||
unsigned char b[32]; | |||||
secp256k1_num n; | |||||
secp256k1_num m; | |||||
/* secp256k1 field prime, value p defined in "Standards for Efficient Cryptography" (SEC2) 2.7.1. */ | |||||
static const unsigned char prime[32] = { | |||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, | |||||
0xFF,0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F | |||||
}; | |||||
secp256k1_fe c = *a; | |||||
secp256k1_fe_normalize_var(&c); | |||||
secp256k1_fe_get_b32(b, &c); | |||||
secp256k1_num_set_bin(&n, b, 32); | |||||
secp256k1_num_set_bin(&m, prime, 32); | |||||
return secp256k1_num_jacobi(&n, &m) >= 0; | |||||
#else | |||||
secp256k1_fe r; | secp256k1_fe r; | ||||
return secp256k1_fe_sqrt(&r, a); | return secp256k1_fe_sqrt(&r, a); | ||||
#endif | |||||
} | } | ||||
static const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1); | static const secp256k1_fe secp256k1_fe_one = SECP256K1_FE_CONST(0, 0, 0, 0, 0, 0, 0, 1); | ||||
#endif /* SECP256K1_FIELD_IMPL_H */ | #endif /* SECP256K1_FIELD_IMPL_H */ |