diff --git a/pkg/urbit/include/noun/log.h b/pkg/urbit/include/noun/log.h index 204cb8505..07ab2296c 100644 --- a/pkg/urbit/include/noun/log.h +++ b/pkg/urbit/include/noun/log.h @@ -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); diff --git a/pkg/urbit/jets/e/aes_cbc.c b/pkg/urbit/jets/e/aes_cbc.c index 793304ad4..b561efa44 100644 --- a/pkg/urbit/jets/e/aes_cbc.c +++ b/pkg/urbit/jets/e/aes_cbc.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/aes_ecb.c b/pkg/urbit/jets/e/aes_ecb.c index 9ea9c59ed..d350bc808 100644 --- a/pkg/urbit/jets/e/aes_ecb.c +++ b/pkg/urbit/jets/e/aes_ecb.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/aes_siv.c b/pkg/urbit/jets/e/aes_siv.c index 326c2311b..a891eb431 100644 --- a/pkg/urbit/jets/e/aes_siv.c +++ b/pkg/urbit/jets/e/aes_siv.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/argon2.c b/pkg/urbit/jets/e/argon2.c index b9c9415ac..e2f2e9bf3 100644 --- a/pkg/urbit/jets/e/argon2.c +++ b/pkg/urbit/jets/e/argon2.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/blake.c b/pkg/urbit/jets/e/blake.c index eb36ba87d..1770a3f89 100644 --- a/pkg/urbit/jets/e/blake.c +++ b/pkg/urbit/jets/e/blake.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/ed_add_double_scalarmult.c b/pkg/urbit/jets/e/ed_add_double_scalarmult.c index af73d5964..e3f01950d 100644 --- a/pkg/urbit/jets/e/ed_add_double_scalarmult.c +++ b/pkg/urbit/jets/e/ed_add_double_scalarmult.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c b/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c index 2db437aec..26dd69994 100644 --- a/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_add_scalarmult_scalarmult_base.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/ed_point_add.c b/pkg/urbit/jets/e/ed_point_add.c index 2a5da2938..dfa52502e 100644 --- a/pkg/urbit/jets/e/ed_point_add.c +++ b/pkg/urbit/jets/e/ed_point_add.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/ed_scalarmult.c b/pkg/urbit/jets/e/ed_scalarmult.c index 97c88c4f6..136d51af2 100644 --- a/pkg/urbit/jets/e/ed_scalarmult.c +++ b/pkg/urbit/jets/e/ed_scalarmult.c @@ -35,6 +35,6 @@ { return u3m_bail(c3__exit); } else { - return _cqee_scalarmult(a, b); + return u3l_punt("scalarmult", _cqee_scalarmult(a, b)); } } diff --git a/pkg/urbit/jets/e/ed_scalarmult_base.c b/pkg/urbit/jets/e/ed_scalarmult_base.c index 9756e65a5..965ba8b22 100644 --- a/pkg/urbit/jets/e/ed_scalarmult_base.c +++ b/pkg/urbit/jets/e/ed_scalarmult_base.c @@ -30,6 +30,6 @@ return u3m_bail(c3__exit); } else { - return _cqee_scalarmult_base(a); + return u3l_punt("scalarmult-base", _cqee_scalarmult_base(a)); } } diff --git a/pkg/urbit/jets/e/ed_shar.c b/pkg/urbit/jets/e/ed_shar.c index 7db4e6175..e26b0627c 100644 --- a/pkg/urbit/jets/e/ed_shar.c +++ b/pkg/urbit/jets/e/ed_shar.c @@ -35,6 +35,6 @@ { return u3m_bail(c3__exit); } else { - return _cqee_shar(pub, sek); + return u3l_punt("shar", _cqee_shar(pub, sek)); } } diff --git a/pkg/urbit/jets/e/ed_veri.c b/pkg/urbit/jets/e/ed_veri.c index c4a4b6f2d..51ac20c13 100644 --- a/pkg/urbit/jets/e/ed_veri.c +++ b/pkg/urbit/jets/e/ed_veri.c @@ -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)); } } diff --git a/pkg/urbit/jets/e/ripe.c b/pkg/urbit/jets/e/ripe.c index 971a04b2c..457068d47 100644 --- a/pkg/urbit/jets/e/ripe.c +++ b/pkg/urbit/jets/e/ripe.c @@ -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)); } } diff --git a/pkg/urbit/noun/log.c b/pkg/urbit/noun/log.c index 8d58fef29..866a7430e 100644 --- a/pkg/urbit/noun/log.c +++ b/pkg/urbit/noun/log.c @@ -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; +}