Come generare la chiave pubblica privata ec256 in formato esadecimale

1

Qualcuno potrebbe dirmi come generare coppie di chiavi come questa in formato esadecimale: Questo è da SampleCode / RemoteAttestation / service_provider / service_provider.cpp dal repository: link

// 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
    }
};

Sono nuovo della crittografia. La definizione del tipo di dati:

#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)
    
posta Roshan Mehta 13.04.2018 - 04:34
fonte

1 risposta

1

Questo sta usando la curva NIST P-256 alias secp256r1 ( RFC 4492 ) alias prime256v1 .

Puoi creare coppie di chiavi e stamparle in formato esadecimale usando OpenSSL, ad es.

$ 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

Ovviamente non sono in un così bel allineamento 4x8, ma abbastanza facile da sostituire : 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

e poi fai il resto manualmente, se usi questo codice nel tuo programma:

    {
        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
    }
    
risposta data 13.04.2018 - 10:28
fonte

Leggi altre domande sui tag