Skip to content

Commit

Permalink
openssl, feat: add ed25519 to x25519 convert function.
Browse files Browse the repository at this point in the history
  • Loading branch information
xicilion committed Mar 18, 2024
1 parent 5b64f0a commit dcc47fa
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions openssl/src/crypto/ec/curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -5715,3 +5715,38 @@ ossl_x25519_public_from_private(uint8_t out_public_value[32],

OPENSSL_cleanse(e, sizeof(e));
}

void
ossl_x25519_private_from_ed25519(uint8_t out_private_key[32],
const uint8_t private_key[32])
{
uint8_t md[SHA512_DIGEST_LENGTH];

SHA512(private_key, 32, md);

md[0] &= 248;
md[31] &= 127;
md[31] |= 64;

memcpy(out_private_key, md, 32);

OPENSSL_cleanse(md, sizeof(md));
}

void
ossl_x25519_public_from_ed25519(uint8_t out_public_value[32],
const uint8_t public_value[32])
{
fe Z, Y;
fe zplusy, zminusy, zminusy_inv;

fe_frombytes(Y, public_value);
fe_1(Z);

fe_add(zplusy, Z, Y);
fe_sub(zminusy, Z, Y);
fe_invert(zminusy_inv, zminusy);
fe_mul(zplusy, zplusy, zminusy_inv);

fe_tobytes(out_public_value, zplusy);
}

0 comments on commit dcc47fa

Please sign in to comment.