Skip to content

Commit

Permalink
deploy: b3671f8
Browse files Browse the repository at this point in the history
  • Loading branch information
dajiaji committed Jul 30, 2023
1 parent 6fe32e5 commit a51455f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
86 changes: 86 additions & 0 deletions dhkem-x25519/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<html>
<head><title>@hpke/dhkem-x25519 test</title></head>
<body>
<script type="module">
import { KdfId, AeadId, CipherSuite } from './src/hpke-core.js';
import { DhkemX25519HkdfSha256 } from './src/hpke-dhkem-x25519.js';

const kdfs = [
KdfId.HkdfSha256,
KdfId.HkdfSha384,
KdfId.HkdfSha512,
];

const aeads = [
AeadId.Aes128Gcm,
AeadId.Aes256Gcm,
];

globalThis.run = async () => {
let pass = 0;
let fail = 0;
const kem = new DhkemX25519HkdfSha256();
for (const kdf of kdfs) {
for (const aead of aeads) {
try {
const suite = new CipherSuite({ kem: kem, kdf: kdf, aead: aead });

const rkp = await suite.generateKeyPair();

const sender = await suite.createSenderContext({
recipientPublicKey: rkp.publicKey
});

const recipient = await suite.createRecipientContext({
recipientKey: rkp,
enc: sender.enc,
});

// encrypt
const ct = await sender.seal(new TextEncoder().encode('hello world!'));

// decrypt
const pt = await recipient.open(ct);

// hello world!
'hello world!' === new TextDecoder().decode(pt) ? pass++ : fail++;

} catch (e) {
fail++;
}
}
}
document.getElementById("pass").innerHTML = pass;
document.getElementById("fail").innerHTML = fail;
}

globalThis.reset = () => {
document.getElementById("pass").innerHTML = "-";
document.getElementById("fail").innerHTML = "-";
}

</script>

<h1><a href="https://github.com/dajiaji/hpke-js">@hpke/dhkem-x25519</a> test</h1>

<div id="operation">
<button type="button" onclick="run()">run</button>
<button type="button" onclick="reset()">reset</button>
</div>

<br>

<div id="test">
<table>
<tr>
<th><font color="green">pass: </font></th>
<td id="pass">-</td>
</tr>
<tr>
<th><font color="red">fail: </font></th>
<td id="fail">-</td>
</tr>
</table>
</div>
</body>
</html>
Empty file added dhkem-x25519/src/.gitkeep
Empty file.
Loading

0 comments on commit a51455f

Please sign in to comment.