Esempio n. 1
0
int crypto_ed25519_export_public_key(const ed25519_key *key, byte *buffer, size_t *size) {
    if (size == NULL) {
        return -1;
    }

    if (*size < ED25519_PUB_KEY_SIZE) {
        *size = ED25519_PUB_KEY_SIZE;
        return -2;
    }

    word32 len = *size;
    int r = wc_ed25519_export_public((ed25519_key *)key, buffer, &len);
    *size = len;
    return r;
}
Esempio n. 2
0
/* export full private key and public key
   return 0 on success
 */
int wc_ed25519_export_key(ed25519_key* key,
                          byte* priv, word32 *privSz,
                          byte* pub, word32 *pubSz)
{
    int ret;

    /* export 'full' private part */
    ret = wc_ed25519_export_private(key, priv, privSz);
    if (ret != 0)
        return ret;

    /* export public part */
    ret = wc_ed25519_export_public(key, pub, pubSz);

    return ret;
}
Esempio n. 3
0
}

bool uc_import_ecc_pub_key_encoded(uc_ed25519_key *key, uc_ed25519_pub_pkcs8 *pkcs8) {
  return uc_import_ecc_pub_key(key, (const unsigned char *) &(pkcs8->key), sizeof(pkcs8->key));
}


bool uc_ecc_export_pub(ed25519_key *key, uc_ed25519_pub_pkcs8 *pkcs8) {
  // copy the ASN.1 (PKCS#8) header into the encoded public key array
  memcpy(pkcs8->header, (const unsigned char[]) {
    0x30, 13 + ED25519_PUB_KEY_SIZE, 0x30, 0x08, 0x06, 0x03, 0x2b, 0x65, 0x64, 0x0a, 0x01, 0x01,
    0x03, 1 + ED25519_PUB_KEY_SIZE, 0x00
  }, 15);

  word32 len = ED25519_PUB_KEY_SIZE;
  const int status = wc_ed25519_export_public(key, pkcs8->key, &len);
  if (status < 0 || len != ED25519_PUB_KEY_SIZE) {
    UCERROR("ecc pub export", status);
    return false;
  }
  UCDUMP("ECCPUB", (const unsigned char *) pkcs8, sizeof(uc_ed25519_pub_pkcs8));

  return true;
}

char *uc_ecc_export_pub_encoded(ed25519_key *key) {
  uc_ed25519_pub_pkcs8 pkcs8;
  uc_ecc_export_pub(key, &pkcs8);

  return uc_base64_encode((const unsigned char *) &pkcs8, sizeof(pkcs8));
}