From 7f9ef0635c0b0ba4bde24a1878411f38c5dc7c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Paraniak?= Date: Tue, 13 Aug 2024 20:27:34 +0800 Subject: [PATCH 1/3] jets: jet +adler32:adler:checksum in zuse --- pkg/noun/jets/e/adler.c | 127 ++++++++++++++++++++++++++++++++++++++++ pkg/noun/jets/tree.c | 11 ++++ pkg/noun/jets/w.h | 2 + 3 files changed, 140 insertions(+) create mode 100644 pkg/noun/jets/e/adler.c diff --git a/pkg/noun/jets/e/adler.c b/pkg/noun/jets/e/adler.c new file mode 100644 index 0000000000..d7e12118e6 --- /dev/null +++ b/pkg/noun/jets/e/adler.c @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +#include + +static void _x_octs(u3_noun octs, u3_atom* p_octs, u3_atom* q_octs) { + + if (c3n == u3r_mean(octs, + 2, p_octs, + 3, q_octs, 0)){ + u3m_bail(c3__exit); + } + + if (c3n == u3a_is_atom(*p_octs) || + c3n == u3a_is_atom(*q_octs)) { + u3m_bail(c3__exit); + } +} + +static c3_o _x_octs_buffer(u3_atom* p_octs, u3_atom *q_octs, + c3_w* p_octs_w, c3_y** buf_y, + c3_w* len_w, c3_w* lead_w) +{ + if (c3n == u3r_safe_word(*p_octs, p_octs_w)) { + return c3n; + } + + *len_w = u3r_met(3, *q_octs); + + if (c3y == u3a_is_cat(*q_octs)) { + *buf_y = (c3_y*)q_octs; + } + else { + u3a_atom* ptr_a = u3a_to_ptr(*q_octs); + *buf_y = (c3_y*)ptr_a->buf_w; + } + + *lead_w = 0; + + if (*p_octs_w > *len_w) { + *lead_w = *p_octs_w - *len_w; + } + else { + *len_w = *p_octs_w; + } + + return c3y; +} + +#define BASE 65521 +#define NMAX 5552 + +u3_noun _qe_adler32(u3_noun octs) +{ + u3_atom p_octs, q_octs; + + _x_octs(octs, &p_octs, &q_octs); + + c3_w p_octs_w, len_w, lead_w; + c3_y *buf_y; + + if (c3n == _x_octs_buffer(&p_octs, &q_octs, + &p_octs_w, &buf_y, + &len_w, &lead_w)) { + return u3_none; + } + + c3_w adler_w, sum2_w; + + adler_w = 0x1; + sum2_w = 0x0; + + c3_w pos_w = 0; + + // Process all non-zero bytes + // + while (pos_w < len_w) { + + c3_w rem_w = (len_w - pos_w); + + if (rem_w > NMAX) { + rem_w = NMAX; + } + + while (rem_w--) { + adler_w += *(buf_y + pos_w++); + sum2_w += adler_w; + } + + adler_w %= BASE; + sum2_w %= BASE; + } + + // Process leading zeros + // + while (pos_w < p_octs_w) { + + c3_w rem_w = (p_octs_w - pos_w); + + if (rem_w > NMAX) { + rem_w = NMAX; + } + + // leading zeros: adler sum is unchanged + sum2_w += rem_w*adler_w; + pos_w += rem_w; + + adler_w %= BASE; + sum2_w %= BASE; + } + + return u3i_word(sum2_w << 16 | adler_w); +} + + +u3_noun +u3we_adler32(u3_noun cor) +{ + u3_noun octs; + + u3x_mean(cor, u3x_sam, &octs, 0); + + return _qe_adler32(octs); +} diff --git a/pkg/noun/jets/tree.c b/pkg/noun/jets/tree.c index e40fe03846..3f15d003e0 100644 --- a/pkg/noun/jets/tree.c +++ b/pkg/noun/jets/tree.c @@ -2341,6 +2341,16 @@ static u3j_core _138_hex_blake_d[] = {} }; +static u3j_harm _138_hex_adler32_a[] = {{".2", u3we_adler32, c3y}, {}}; +static u3j_core _138_hex_adler_d[] = + { { "adler32", 7, _138_hex_adler32_a, 0, no_hashes }, + {} + }; +static u3j_core _138_hex_checksum_d[] = + { { "adler", 7, 0, _138_hex_adler_d, no_hashes }, + {} + }; + static u3j_core _138_hex_d[] = { { "lore", 63, _140_hex_lore_a, 0, no_hashes }, { "leer", 63, _140_hex_leer_a, 0, no_hashes }, @@ -2359,6 +2369,7 @@ static u3j_core _138_hex_d[] = { "secp", 6, 0, _140_hex_secp_d, no_hashes }, { "mimes", 31, 0, _140_hex_mimes_d, no_hashes }, { "json", 31, 0, _139_hex_json_d, no_hashes }, + { "checksum", 15, 0, _138_hex_checksum_d, no_hashes}, {} }; diff --git a/pkg/noun/jets/w.h b/pkg/noun/jets/w.h index 34716971bd..8072718328 100644 --- a/pkg/noun/jets/w.h +++ b/pkg/noun/jets/w.h @@ -211,6 +211,8 @@ u3_noun u3we_blake3_chunk_output(u3_noun); u3_noun u3we_blake3_compress(u3_noun); + u3_noun u3we_adler32(u3_noun); + u3_noun u3we_ripe(u3_noun); u3_noun u3we_make(u3_noun); From f5d289c903c619569edc5766613229b5332dbdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Paraniak?= Date: Wed, 14 Aug 2024 15:29:13 +0800 Subject: [PATCH 2/3] bazel: add zlib to dependencies --- pkg/noun/BUILD.bazel | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/noun/BUILD.bazel b/pkg/noun/BUILD.bazel index a6b8de6d7a..fd6963cb82 100644 --- a/pkg/noun/BUILD.bazel +++ b/pkg/noun/BUILD.bazel @@ -40,6 +40,7 @@ vere_library( "@sigsegv", "@softfloat", "@urcrypt", + "@zlib", ] + select({ "@platforms//os:macos": ["//pkg/noun/platform/darwin"], "@platforms//os:linux": ["//pkg/noun/platform/linux"], From 42d5c387e22917e286295dbfd105ffafc11d8a60 Mon Sep 17 00:00:00 2001 From: levernathan Date: Wed, 14 Aug 2024 15:31:58 +0800 Subject: [PATCH 3/3] jets: jet +crc32:crc:checksum --- pkg/noun/jets/e/crc.c | 56 +++++++++++++++++++++++++++++++++++++++++++ pkg/noun/jets/tree.c | 20 +++++++++++----- pkg/noun/jets/w.h | 1 + 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 pkg/noun/jets/e/crc.c diff --git a/pkg/noun/jets/e/crc.c b/pkg/noun/jets/e/crc.c new file mode 100644 index 0000000000..b97b2cd21a --- /dev/null +++ b/pkg/noun/jets/e/crc.c @@ -0,0 +1,56 @@ +/// @file + +#include +#include +#include "zlib.h" + +#include "jets/w.h" + +#include "noun.h" + +u3_noun +u3qe_crc32(u3_noun input_octs) +{ + u3_atom tail = u3t(input_octs); + c3_w len_w = u3r_met(3, tail); + c3_y* input; + + if (c3y == u3a_is_cat(tail)) { + input = (c3_y*)&tail; + } + else { + u3a_atom* vat_u = u3a_to_ptr(tail); + input = (c3_y*)vat_u->buf_w; + } + + c3_w p_octs_w; + + if (c3n == u3r_safe_word(u3h(input_octs), &p_octs_w)) { + return u3_none; + } + + c3_w lead_w = p_octs_w - len_w; + c3_w crc = 0L; + + crc = crc32(crc, input, len_w); + + c3_w zero_w = 0; + while (lead_w-- > 0) { + crc = crc32(crc, &zero_w, 1); + } + + return u3i_word(crc); +} + +u3_noun +u3we_crc32(u3_noun cor) +{ + u3_noun a = u3r_at(u3x_sam, cor); + + if ( (u3du(a) == c3y) && (u3ud(u3h(a))) == c3y && (u3ud(u3t(a))) == c3y) { + return u3qe_crc32(a); + } + else { + return u3m_bail(c3__exit); + } +} diff --git a/pkg/noun/jets/tree.c b/pkg/noun/jets/tree.c index 3f15d003e0..3993440f2f 100644 --- a/pkg/noun/jets/tree.c +++ b/pkg/noun/jets/tree.c @@ -2341,13 +2341,20 @@ static u3j_core _138_hex_blake_d[] = {} }; -static u3j_harm _138_hex_adler32_a[] = {{".2", u3we_adler32, c3y}, {}}; -static u3j_core _138_hex_adler_d[] = - { { "adler32", 7, _138_hex_adler32_a, 0, no_hashes }, +static u3j_harm _137_hex__adler32_a[] = {{".2", u3we_adler32, c3y}, {}}; +static u3j_core _137_hex__adler_d[] = + { { "adler32", 7, _137_hex__adler32_a, 0, no_hashes }, {} }; -static u3j_core _138_hex_checksum_d[] = - { { "adler", 7, 0, _138_hex_adler_d, no_hashes }, +static u3j_harm _137_hex__crc32_a[] = {{".2", u3we_crc32}, {}}; +static u3j_core _137_hex__crc_d[] = + { {"crc32", 7, _137_hex__crc32_a, 0, no_hashes }, + {} + }; + +static u3j_core _137_hex_checksum_d[] = + { { "adler", 3, 0, _137_hex__adler_d, no_hashes }, + { "crc", 3, 0, _137_hex__crc_d, no_hashes}, {} }; @@ -2369,7 +2376,7 @@ static u3j_core _138_hex_d[] = { "secp", 6, 0, _140_hex_secp_d, no_hashes }, { "mimes", 31, 0, _140_hex_mimes_d, no_hashes }, { "json", 31, 0, _139_hex_json_d, no_hashes }, - { "checksum", 15, 0, _138_hex_checksum_d, no_hashes}, + { "checksum", 15, 0, _137_hex_checksum_d, no_hashes}, {} }; @@ -2632,6 +2639,7 @@ static u3j_core _d[] = { { "k140", 0, 0, _k140_d, _k140_ha, 0, (u3j_core*) 140, 0 }, { "k139", 0, 0, _k139_d, no_hashes, 0, (u3j_core*) 139, 0 }, { "k138", 0, 0, _k138_d, no_hashes, 0, (u3j_core*) 138, 0 }, + { "k137", 0, 0, _k138_d, no_hashes, 0, (u3j_core*) 137, 0 }, { "a50", 0, 0, _a50_d, _k140_ha, 0, (u3j_core*) c3__a50, 0 }, {} }; diff --git a/pkg/noun/jets/w.h b/pkg/noun/jets/w.h index 8072718328..3898cb8633 100644 --- a/pkg/noun/jets/w.h +++ b/pkg/noun/jets/w.h @@ -212,6 +212,7 @@ u3_noun u3we_blake3_compress(u3_noun); u3_noun u3we_adler32(u3_noun); + u3_noun u3we_crc32(u3_noun); u3_noun u3we_ripe(u3_noun);