Cómo generar la clave pública privada ec256 en formato hexadecimal

1

Alguien podría decirme cómo generar un par de claves como esta en formato hexadecimal: Esto es de SampleCode / RemoteAttestation / service_provider / service_provider.cpp del repositorio: enlace

// This is the private EC key of SP, the corresponding public EC key is
// hard coded in isv_enclave. It is based on NIST P-256 curve.
    static const sample_ec256_private_t g_sp_priv_key = {
        {
            0x90, 0xe7, 0x6c, 0xbb, 0x2d, 0x52, 0xa1, 0xce,
            0x3b, 0x66, 0xde, 0x11, 0x43, 0x9c, 0x87, 0xec,
            0x1f, 0x86, 0x6a, 0x3b, 0x65, 0xb6, 0xae, 0xea,
            0xad, 0x57, 0x34, 0x53, 0xd1, 0x03, 0x8c, 0x01
        }
    };

// This is the public EC key of SP, this key is hard coded in isv_enclave.
// It is based on NIST P-256 curve. Not used in the SP code.
static const sample_ec_pub_t g_sp_pub_key = {
    {
        0x72, 0x12, 0x8a, 0x7a, 0x17, 0x52, 0x6e, 0xbf,
        0x85, 0xd0, 0x3a, 0x62, 0x37, 0x30, 0xae, 0xad,
        0x3e, 0x3d, 0xaa, 0xee, 0x9c, 0x60, 0x73, 0x1d,
        0xb0, 0x5b, 0xe8, 0x62, 0x1c, 0x4b, 0xeb, 0x38
    },
    {
        0xd4, 0x81, 0x40, 0xd9, 0x50, 0xe2, 0x57, 0x7b,
        0x26, 0xee, 0xb7, 0x41, 0xe7, 0xc6, 0x14, 0xe2,
        0x24, 0xb7, 0xbd, 0xc9, 0x03, 0xf2, 0x9a, 0x28,
        0xa8, 0x3c, 0xc8, 0x10, 0x11, 0x14, 0x5e, 0x06
    }
};

Soy nuevo en criptografía. La definición del tipo de datos:

#define SAMPLE_ECP256_KEY_SIZE             32
typedef struct sample_ec256_private_t
{
    uint8_t r[SAMPLE_ECP256_KEY_SIZE];
} sample_ec256_private_t;


typedef struct sample_ec_pub_t
{
    uint8_t gx[SAMPLE_ECP_KEY_SIZE];
    uint8_t gy[SAMPLE_ECP_KEY_SIZE];
} sample_ec_pub_t;

 #define SAMPLE_FEBITSIZE                    256
#define SAMPLE_ECP_KEY_SIZE                     (SAMPLE_FEBITSIZE/8)
    
pregunta Roshan Mehta 13.04.2018 - 04:34
fuente

1 respuesta

1

Esto está utilizando la curva NIST P-256, también conocida como secp256r1 ( RFC 4492 ), también conocida como prime256v1 .

Puede crear pares de claves e imprimirlas en formato hexadecimal utilizando OpenSSL, por ejemplo,

$ openssl ecparam -name secp256r1 -genkey | openssl ec -text -noout
using curve name prime256v1 instead of secp256r1
read EC key
Private-Key: (256 bit)
priv:
    2c:23:47:d5:a6:a2:9e:32:28:ae:7b:8d:7b:a2:67:
    87:eb:e6:57:e0:51:76:59:1a:6b:f8:a7:17:9b:d3:
    b9:18
pub:
    04:ab:e6:db:26:cc:b7:4c:d0:03:24:52:8e:96:33:
    50:19:21:ce:50:c5:34:b5:57:b7:bc:ac:63:d1:eb:
    06:e4:53:76:95:46:39:d2:54:38:e0:a7:52:3c:00:
    fe:0a:66:1d:10:cd:ed:ed:75:b5:72:50:e8:ee:17:
    99:d0:39:62:b6
ASN1 OID: prime256v1
NIST CURVE: P-256

Por supuesto, no están en una alineación 4x8 tan hermosa, pero son lo suficientemente fáciles de reemplazar : con , 0x

2c, 0x23, 0x47, 0xd5, 0xa6, 0xa2, 0x9e, 0x32, 0x28, 0xae, 0x7b, 0x8d, 0x7b, 0xa2, 0x67, 0x
87, 0xeb, 0xe6, 0x57, 0xe0, 0x51, 0x76, 0x59, 0x1a, 0x6b, 0xf8, 0xa7, 0x17, 0x9b, 0xd3, 0x
b9, 0x18

y luego haga el resto manualmente, si utiliza este código en su programa:

    {
        0x2c, 0x23, 0x47, 0xd5, 0xa6, 0xa2, 0x9e, 0x32, 
        0x28, 0xae, 0x7b, 0x8d, 0x7b, 0xa2, 0x67, 0x87, 
        0xeb, 0xe6, 0x57, 0xe0, 0x51, 0x76, 0x59, 0x1a,
        0x6b, 0xf8, 0xa7, 0x17, 0x9b, 0xd3, 0xb9, 0x18
    }
    
respondido por el Esa Jokinen 13.04.2018 - 10:28
fuente

Lea otras preguntas en las etiquetas