code cleanup, support keypairs, init support for X25519

This commit is contained in:
Halil Durak
2026-01-13 19:39:28 +03:00
parent fd26ae4b5b
commit 7ae3e8cb47
2 changed files with 54 additions and 0 deletions

View File

@@ -47,6 +47,54 @@
// }
</script>
<script id=SubtleCrypto>
testing.async(async () => {
let key = await crypto.subtle.generateKey(
{
name: "HMAC",
hash: { name: "SHA-512" },
},
true,
["sign", "verify"],
);
//const raw = crypto.subtle.exportKey("adv", key).catch(err => console.warn(err));
//testing.expectEqual(128, raw.byteLength);
const encoder = new TextEncoder();
const signature = await crypto.subtle.sign(
"HMAC",
key,
encoder.encode("Hello, world!")
);
const result = await window.crypto.subtle.verify(
{ name: "HMAC" },
key,
signature,
encoder.encode("Hello, world!")
);
testing.expectEqual(true, true);
});
</script>
<script id=X25519>
testing.async(async () => {
const { privateKey, publicKey } = await crypto.subtle.generateKey(
{ name: "X25519" },
true,
["deriveKey", "deriveBits"],
);
console.warn(privateKey);
console.warn(publicKey);
testing.expectEqual(true, true);
});
</script>
<!-- <script id="randomUUID">
const uuid = crypto.randomUUID();
testing.expectEqual('string', typeof uuid);

View File

@@ -26,3 +26,9 @@ pub extern fn HMAC(
out: [*]u8,
out_len: *c_uint,
) ?[*]u8;
pub const X25519_PRIVATE_KEY_LEN = 32;
pub const X25519_PUBLIC_VALUE_LEN = 32;
pub const X25519_SHARED_KEY_LEN = 32;
pub extern fn X25519_keypair(out_public_value: *[32]u8, out_private_key: *[32]u8) void;