normalize punt logging with u3l_punt

This commit is contained in:
Paul Driver 2020-08-26 10:51:42 -07:00
parent 367db56954
commit 9f251af61d
15 changed files with 59 additions and 51 deletions

View File

@ -2,8 +2,18 @@
**
*/
/* u3_log(): logs to stderr or redirects to configured function.
/* u3l_log(): logs to stderr or redirects to configured function.
*/
void
u3l_log(const char* format, ...)
__attribute__ ((format (printf, 1, 2)));
/* u3l_punt(): condtionally logs a named punt
* (e.g. "mint-punt" for the `name` "mint")
* when `pro` is u3_none, and returns pro.
* For use when a jet driver declines to handle
* a core, when the user should be somehow notified
* (e.g. in a cryptographic jet).
*/
u3_weak
u3l_punt(const char* name, u3_weak pro);

View File

@ -57,7 +57,7 @@ typedef int (*urcrypt_cbc)(c3_y**,
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_cbca_en(a, b, c);
return u3l_punt("cbca-en", _cqea_cbca_en(a, b, c));
}
}
@ -81,7 +81,7 @@ typedef int (*urcrypt_cbc)(c3_y**,
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_cbca_de(a, b, c);
return u3l_punt("cbca-de", _cqea_cbca_de(a, b, c));
}
}
@ -105,7 +105,7 @@ typedef int (*urcrypt_cbc)(c3_y**,
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_cbcb_en(a, b, c);
return u3l_punt("cbcb-en", _cqea_cbcb_en(a, b, c));
}
}
@ -129,7 +129,7 @@ typedef int (*urcrypt_cbc)(c3_y**,
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_cbcb_de(a, b, c);
return u3l_punt("cbcb-de", _cqea_cbcb_de(a, b, c));
}
}
@ -153,7 +153,7 @@ typedef int (*urcrypt_cbc)(c3_y**,
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_cbcc_en(a, b, c);
return u3l_punt("cbcc-en", _cqea_cbcc_en(a, b, c));
}
}
@ -177,6 +177,6 @@ typedef int (*urcrypt_cbc)(c3_y**,
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_cbcc_de(a, b, c);
return u3l_punt("cbcc-de", _cqea_cbcc_de(a, b, c));
}
}

View File

@ -46,7 +46,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]);
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_ecba_en(a, b);
return u3l_punt("ecba-en", _cqea_ecba_en(a, b));
}
}
@ -69,7 +69,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]);
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_ecba_de(a, b);
return u3l_punt("ecba-de", _cqea_ecba_de(a, b));
}
}
@ -92,7 +92,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]);
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_ecbb_en(a, b);
return u3l_punt("ecbb-en", _cqea_ecbb_en(a, b));
}
}
@ -115,7 +115,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]);
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_ecbb_de(a, b);
return u3l_punt("ecbb-de", _cqea_ecbb_de(a, b));
}
}
@ -138,7 +138,7 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]);
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_ecbc_en(a, b);
return u3l_punt("ecbc-en", _cqea_ecbc_en(a, b));
}
}
@ -161,6 +161,6 @@ typedef int (*urcrypt_ecb)(c3_y*, c3_y[16], c3_y[16]);
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_ecbc_de(a, b);
return u3l_punt("ecbc-de", _cqea_ecbc_de(a, b));
}
}

View File

@ -161,15 +161,6 @@ _cqea_siv_de(c3_y* key_y,
}
}
static u3_noun
_cqea_siv_punt(c3_y* nam_y, u3_noun val)
{
if ( u3_none == val ) {
u3l_log("%s-punt\r\n", nam_y);
}
return val;
}
// the siv* hoon doesn't explicitly check keysizes, but all of these functions
// have fixed maximum keysizes, so we will punt if we get a key that is too
// large.
@ -201,7 +192,7 @@ u3wea_siva_en(u3_noun cor)
c3n == u3ud(txt) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_siv_punt("siva-en", _cqea_siva_en(key, ads, txt));
return u3l_punt("siva-en", _cqea_siva_en(key, ads, txt));
}
}
@ -237,7 +228,7 @@ u3wea_siva_de(u3_noun cor)
c3n == u3ud(txt) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_siv_punt("siva-de", _cqea_siva_de(key, ads, iv, len, txt));
return u3l_punt("siva-de", _cqea_siva_de(key, ads, iv, len, txt));
}
}
@ -269,7 +260,7 @@ u3wea_sivb_en(u3_noun cor)
c3n == u3ud(txt) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_siv_punt("sivb-en", _cqea_sivb_en(key, ads, txt));
return u3l_punt("sivb-en", _cqea_sivb_en(key, ads, txt));
}
}
@ -305,7 +296,7 @@ u3wea_sivb_de(u3_noun cor)
c3n == u3ud(txt) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_siv_punt("sivb-de", _cqea_sivb_de(key, ads, iv, len, txt));
return u3l_punt("sivb-de", _cqea_sivb_de(key, ads, iv, len, txt));
}
}
@ -336,7 +327,7 @@ u3wea_sivc_en(u3_noun cor)
c3n == u3ud(txt) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_siv_punt("sivc-en", _cqea_sivc_en(key, ads, txt));
return u3l_punt("sivc-en", _cqea_sivc_en(key, ads, txt));
}
}
@ -372,6 +363,6 @@ u3wea_sivc_de(u3_noun cor)
c3n == u3ud(txt) ) {
return u3m_bail(c3__exit);
} else {
return _cqea_siv_punt("sivc-de", _cqea_sivc_de(key, ads, iv, len, txt));
return u3l_punt("sivc-de", _cqea_sivc_de(key, ads, iv, len, txt));
}
}

View File

@ -55,7 +55,6 @@
u3r_word_fit(&ted_w, threads) &&
u3r_word_fit(&mem_w, mem_cost) &&
u3r_word_fit(&tim_w, time_cost)) ) {
u3l_log("%s\r\n", "argon2-punt");
return u3_none;
}
else {
@ -86,7 +85,7 @@
}
else {
ret = u3_none;
u3l_log("argon2-punt: %s\r\n", err_c);
u3l_log("argon2-error: %s\r\n", err_c);
}
u3a_free(out_y);
@ -130,9 +129,10 @@
return u3m_bail(c3__exit);
}
else {
return _cqe_argon2(out, type, version,
threads, mem_cost, time_cost,
wik, key, wix, extra,
wid, dat, wis, sat);
return u3l_punt("argon2",
_cqe_argon2(out, type, version,
threads, mem_cost, time_cost,
wik, key, wix, extra,
wid, dat, wis, sat));
}
}

View File

@ -34,7 +34,6 @@
return u3i_bytes(out_w, out_y);
}
else {
u3l_log("%s\r\n", "blake2-punt: library error");
return u3_none;
}
}
@ -56,6 +55,6 @@
{
return u3m_bail(c3__exit);
} else {
return _cqe_blake(wid, dat, wik, dak, out);
return u3l_punt("blake", _cqe_blake(wid, dat, wik, dak, out));
}
}

View File

@ -41,6 +41,7 @@
{
return u3m_bail(c3__exit);
} else {
return _cqee_add_double_scalarmult(a, b, c, d);
return u3l_punt("add-double-scalarmult",
_cqee_add_double_scalarmult(a, b, c, d));
}
}

View File

@ -38,6 +38,7 @@
{
return u3m_bail(c3__exit);
} else {
return _cqee_add_scalarmult_scalarmult_base(a, b, c);
return u3l_punt("add-scalarmult-scalarmult-base",
_cqee_add_scalarmult_scalarmult_base(a, b, c));
}
}

View File

@ -35,6 +35,6 @@
{
return u3m_bail(c3__exit);
} else {
return _cqee_point_add(a, b);
return u3l_punt("point-add", _cqee_point_add(a, b));
}
}

View File

@ -35,6 +35,6 @@
{
return u3m_bail(c3__exit);
} else {
return _cqee_scalarmult(a, b);
return u3l_punt("scalarmult", _cqee_scalarmult(a, b));
}
}

View File

@ -30,6 +30,6 @@
return u3m_bail(c3__exit);
}
else {
return _cqee_scalarmult_base(a);
return u3l_punt("scalarmult-base", _cqee_scalarmult_base(a));
}
}

View File

@ -35,6 +35,6 @@
{
return u3m_bail(c3__exit);
} else {
return _cqee_shar(pub, sek);
return u3l_punt("shar", _cqee_shar(pub, sek));
}
}

View File

@ -37,6 +37,6 @@
u3x_sam_7, &c, 0) ) {
return u3m_bail(c3__fail);
} else {
return _cqee_veri(a, b, c);
return u3l_punt("veri", _cqee_veri(a, b, c));
}
}

View File

@ -18,13 +18,10 @@
c3_y out_y[20];
c3_y *dat_y = u3r_bytes_alloc(0, len_w, dat);
if ( 0 == urcrypt_ripemd160(dat_y, len_w, out_y) ) {
ret = u3i_bytes(20, out_y);
}
else {
u3l_log("%s\r\n", "ripemd160-punt");
ret = u3_none;
}
ret = ( 0 == urcrypt_ripemd160(dat_y, len_w, out_y) )
? u3i_bytes(20, out_y)
: u3_none;
u3a_free(dat_y);
return ret;
}
@ -43,6 +40,6 @@
return u3m_bail(c3__exit);
}
else {
return _cqe_ripe(wid, dat);
return u3l_punt("ripe", _cqe_ripe(wid, dat));
}
}

View File

@ -26,3 +26,12 @@ u3l_log(const char* format, ...)
va_end(myargs);
}
u3_weak
u3l_punt(const char* name, u3_weak pro)
{
if ( u3_none == pro ) {
u3l_log("%s-punt\r\n", name);
}
return pro;
}