pike.git / src / post_modules / Nettle / hogweed.cmod

version» Context lines:

pike.git/src/post_modules/Nettle/hogweed.cmod:332:   #include <nettle/ecc.h>      #include <nettle/ecdsa.h>      #define SECP192R1 0   #define SECP224R1 1   #define SECP256R1 2   #define SECP384R1 3   #define SECP521R1 4    + #ifdef NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_192R1 + static const struct ecc_curve *nettle_get_secp_192r1(void) { return nettle_secp_192r1; } + #endif /* NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_192R1 */ + #ifdef NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_224R1 + static const struct ecc_curve *nettle_get_secp_224r1(void) { return nettle_secp_224r1; } + #endif /* NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_224R1 */ + #ifdef NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_256R1 + static const struct ecc_curve *nettle_get_secp_256r1(void) { return nettle_secp_256r1; } + #endif /* NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_256R1 */ + #ifdef NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_384R1 + static const struct ecc_curve *nettle_get_secp_384r1(void) { return nettle_secp_384r1; } + #endif /* NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_384R1 */ + #ifdef NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_521R1 + static const struct ecc_curve *nettle_get_secp_521r1(void) { return nettle_secp_521r1; } + #endif /* NEED_WRAPPER_FOR_CURVE_NETTLE_SECP_521R1 */ +    #ifndef ecc_point_equal_p   static int ecc_point_equal_p(const struct ecc_point *a, const struct ecc_point *b)   {    return (a->ecc == b->ecc) && !mpn_cmp(a->p, b->p, ecc_size_a(a->ecc));   }   #endif      /*! @class ECC_Curve    *!    *! Elliptic Curve Definition
pike.git/src/post_modules/Nettle/hogweed.cmod:389:    {    mpz_t mpz_one;       if (THIS->curve) {    Pike_error("The curve has already been initialized!\n");    }    pop_stack();       switch(curve) {   #ifdef HAVE_CURVE_NETTLE_SECP_192R1 -  case SECP192R1: THIS->curve = &nettle_secp_192r1; break; +  case SECP192R1: THIS->curve = nettle_get_secp_192r1(); break;   #endif /* HAVE_CURVE_NETTLE_SECP_192R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_224R1 -  case SECP224R1: THIS->curve = &nettle_secp_224r1; break; +  case SECP224R1: THIS->curve = nettle_get_secp_224r1(); break;   #endif /* HAVE_CURVE_NETTLE_SECP_224R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_256R1 -  case SECP256R1: THIS->curve = &nettle_secp_256r1; break; +  case SECP256R1: THIS->curve = nettle_get_secp_256r1(); break;   #endif /* HAVE_CURVE_NETTLE_SECP_256R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_384R1 -  case SECP384R1: THIS->curve = &nettle_secp_384r1; break; +  case SECP384R1: THIS->curve = nettle_get_secp_384r1(); break;   #endif /* HAVE_CURVE_NETTLE_SECP_384R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_521R1 -  case SECP521R1: THIS->curve = &nettle_secp_521r1; break; +  case SECP521R1: THIS->curve = nettle_get_secp_521r1(); break;   #endif /* HAVE_CURVE_NETTLE_SECP_521R1 */    default:    Pike_error("Invalid curve\n");    break;    }       ecc_scalar_init(&THIS->scalar_one, THIS->curve);    mpz_init_set_si(mpz_one, 1);   #ifdef PIKE_DEBUG    if( !ecc_scalar_set(&THIS->scalar_one, mpz_one) )
pike.git/src/post_modules/Nettle/hogweed.cmod:472:    /*! @decl string(7bit) name()    *!    *! Returns the name of the curve.    *!    *! @seealso    *! @[jose_name()]    */    PIKEFUN string(7bit) name()    {   #ifdef HAVE_CURVE_NETTLE_SECP_192R1 -  if (THIS->curve == &nettle_secp_192r1) { +  if (THIS->curve == nettle_get_secp_192r1()) {    ref_push_string(MK_STRING("SECP_192R1"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_192R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_224R1 -  if (THIS->curve == &nettle_secp_224r1) { +  if (THIS->curve == nettle_get_secp_224r1()) {    ref_push_string(MK_STRING("SECP_224R1"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_224R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_256R1 -  if (THIS->curve == &nettle_secp_256r1) { +  if (THIS->curve == nettle_get_secp_256r1()) {    ref_push_string(MK_STRING("SECP_256R1"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_256R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_384R1 -  if (THIS->curve == &nettle_secp_384r1) { +  if (THIS->curve == nettle_get_secp_384r1()) {    ref_push_string(MK_STRING("SECP_384R1"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_384R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_521R1 -  if (THIS->curve == &nettle_secp_521r1) { +  if (THIS->curve == nettle_get_secp_521r1()) {    ref_push_string(MK_STRING("SECP_521R1"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_521R1 */    ref_push_string(MK_STRING("UNKNOWN"));    }       /*! @decl string(7bit) jose_name()    *!    *! Returns the name of the curve according to JOSE
pike.git/src/post_modules/Nettle/hogweed.cmod:519:    *! @returns    *! Returns the JOSE name for supported curves,    *! and @[UNDEFINED] otherwise.    *!    *! @seealso    *! @[name()]    */    PIKEFUN string(7bit) jose_name()    {   #ifdef HAVE_CURVE_NETTLE_SECP_256R1 -  if (THIS->curve == &nettle_secp_256r1) { +  if (THIS->curve == nettle_get_secp_256r1()) {    ref_push_string(MK_STRING("P-256"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_256R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_384R1 -  if (THIS->curve == &nettle_secp_384r1) { +  if (THIS->curve == nettle_get_secp_384r1()) {    ref_push_string(MK_STRING("P-384"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_384R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_521R1 -  if (THIS->curve == &nettle_secp_521r1) { +  if (THIS->curve == nettle_get_secp_521r1()) {    ref_push_string(MK_STRING("P-521"));    return;    }   #endif /* HAVE_CURVE_NETTLE_SECP_521R1 */    push_undefined();    }       /*! @decl int size()    *!    *! @returns    *! Returns the size in bits for a single coordinate on the curve.    */    PIKEFUN int size()    {   #ifdef HAVE_NETTLE_ECC_BIT_SIZE    push_int(ecc_bit_size(THIS->curve));   #else    do {   #ifdef HAVE_CURVE_NETTLE_SECP_192R1 -  if (THIS->curve == &nettle_secp_192r1) { +  if (THIS->curve == nettle_get_secp_192r1()) {    push_int(192);    break;    }   #endif /* HAVE_CURVE_NETTLE_SECP_192R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_224R1 -  if (THIS->curve == &nettle_secp_224r1) { +  if (THIS->curve == nettle_get_secp_224r1()) {    push_int(224);    break;    }   #endif /* HAVE_CURVE_NETTLE_SECP_224R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_256R1 -  if (THIS->curve == &nettle_secp_256r1) { +  if (THIS->curve == nettle_get_secp_256r1()) {    push_int(256);    break;    }   #endif /* HAVE_CURVE_NETTLE_SECP_256R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_384R1 -  if (THIS->curve == &nettle_secp_384r1) { +  if (THIS->curve == nettle_get_secp_384r1()) {    push_int(384);    break;    }   #endif /* HAVE_CURVE_NETTLE_SECP_384R1 */   #ifdef HAVE_CURVE_NETTLE_SECP_521R1 -  if (THIS->curve == &nettle_secp_521r1) { +  if (THIS->curve == nettle_get_secp_521r1()) {    push_int(521);    break;    }   #endif /* HAVE_CURVE_NETTLE_SECP_521R1 */    push_int(0);    } while(0);   #endif /* HAVE_NETTLE_ECC_BIT_SIZE */    }       /*! @decl Gmp.mpz new_scalar(function(int(0..):string(8bit)) rnd)