Branch: Tag:

2016-12-23

2016-12-23 14:27:32 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Crypto.ECC.Curve: Added some more support for JOSE.

Added jose_name(), which returns the RFC 7518 name for the curve.

It is now possible to initialize a Point from a JWK.

451:    /*! @decl string(7bit) name()    *!    *! Returns the name of the curve. +  *! +  *! @seealso +  *! @[jose_name()]    */    PIKEFUN string(7bit) name()    {
487:    ref_push_string(MK_STRING("UNKNOWN"));    }    +  /*! @decl string(7bit) jose_name() +  *! +  *! Returns the name of the curve according to JOSE +  *! (@rfc{7518:6.2.1.1@}). +  *! +  *! @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) { +  ref_push_string(MK_STRING("P-256R")); +  return; +  } + #endif /* HAVE_CURVE_NETTLE_SECP_256R1 */ + #ifdef HAVE_CURVE_NETTLE_SECP_384R1 +  if (THIS->curve == &nettle_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) { +  ref_push_string(MK_STRING("P-521")); +  return; +  } + #endif /* HAVE_CURVE_NETTLE_SECP_521R1 */ +  push_undefined(); +  } +     /*! @decl int size()    *!    *! @returns