yggm/libs/edsign.cu

26 lines
931 B
Plaintext
Raw Normal View History

2025-03-14 22:52:59 +05:00
#include <edsign.cuh>
#include <ed25519.cuh>
#include <sha512.cuh>
2025-03-15 05:23:11 +05:00
__device__ __forceinline__ void expand_key(unsigned char* expanded, const unsigned char* secret) {
2025-03-14 22:52:59 +05:00
struct sha512_state s;
2025-03-15 04:42:31 +05:00
memcpy(&s, &sha512_initial_state, sizeof(s));
sha512_final(&s, secret);
sha512_get(&s, expanded);
2025-03-15 14:40:30 +05:00
expanded[0] &= 0xf8;
expanded[31] &= 0x7f;
expanded[31] |= 0x40;
2025-03-14 22:52:59 +05:00
}
2025-03-15 05:23:11 +05:00
__device__ __forceinline__ void sm_pack(unsigned char* r, const unsigned char* k) {
2025-03-14 22:52:59 +05:00
struct ed25519_pt p;
2025-03-15 14:40:30 +05:00
ed25519_smult(&p, k);
2025-03-15 15:35:48 +05:00
unsigned char x[32], y[32];
ed25519_unproject(x, y, &p);
ed25519_pack(r, x, y);
2025-03-14 22:52:59 +05:00
}
__device__ void ed25519_keygen(unsigned char private_key[64], unsigned char public_key[32], unsigned char random_seed[32]) {
2025-03-15 15:35:48 +05:00
unsigned char expanded[64];
expand_key(expanded, random_seed);
sm_pack(public_key, expanded);
2025-03-14 22:52:59 +05:00
memcpy(private_key, random_seed, 32);
memcpy(private_key + 32, public_key, 32);
}