jets: add rounds parameter to xchacha

This commit is contained in:
lukechampine 2024-05-21 00:29:33 -04:00
parent ce235e720e
commit 1a36dfad9a
2 changed files with 13 additions and 7 deletions

View File

@ -327,10 +327,10 @@ versioned_http_file(
versioned_http_archive(
name = "urcrypt",
build_file = "//bazel/third_party/urcrypt:urcrypt.BUILD",
sha256 = "6f054aeca23081265e9c7ed76dd156ac051b64b49d82375f761163d4988fef62",
sha256 = "3c66dd6acdb4703c68f24958c820e79b6a56285ea5d0ba769f60eafe3f0cc0db",
strip_prefix = "urcrypt-{version}",
url = "https://github.com/urbit/urcrypt/archive/{version}.tar.gz",
version = "c6052b52645d1097602b15cc590ccf05495117ba",
version = "a17279dcbf38d812c7019a3e71d25bdfdb8842ef",
)
versioned_http_archive(

View File

@ -44,25 +44,31 @@
static u3_noun
_cqe_chacha_xchacha(u3_atom key, u3_atom nonce)
_cqe_chacha_xchacha(u3_atom rounds, u3_atom key, u3_atom nonce)
{
c3_w rounds_w;
if ( !u3r_word_fit(&rounds_w, rounds) ) {
return u3m_bail(c3__fail);
}
c3_y key_y[32], nonce_y[64], xkey_y[32], xnonce_y[8];
u3r_bytes(0, 32, key_y, key);
u3r_bytes(0, 24, nonce_y, nonce);
urcrypt_chacha_xchacha(key_y, nonce_y, xkey_y, xnonce_y);
urcrypt_chacha_xchacha(rounds, key_y, nonce_y, xkey_y, xnonce_y);
return u3i_cell(u3i_bytes(32, xkey_y), u3i_bytes(8, xnonce_y));
}
u3_noun
u3we_chacha_xchacha(u3_noun cor)
{
u3_noun key, nonce;
if ( c3n == u3r_mean(cor, u3x_sam_2, &key, u3x_sam_3, &nonce, 0) ||
u3_noun sam = u3x_at(u3x_sam, cor);
u3_noun rounds, key, nonce;
if ( c3n == u3r_trel(sam, &rounds, &key, &nonce) ||
c3n == u3ud(rounds) ||
c3n == u3ud(key) ||
c3n == u3ud(nonce) )
{
return u3m_bail(c3__exit);
} else {
return u3l_punt("chacha_xchacha", _cqe_chacha_xchacha(key, nonce));
return u3l_punt("chacha_xchacha", _cqe_chacha_xchacha(rounds, key, nonce));
}
}