Skip to content

Commit

Permalink
jets: add rounds parameter to xchacha
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed May 21, 2024
1 parent ce235e7 commit 874c2a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 11 additions & 5 deletions pkg/noun/jets/e/chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, 0) ||
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));
}
}

0 comments on commit 874c2a2

Please sign in to comment.