Skip to content

Commit

Permalink
fix: add warning when importing zcash compressed octets in ECP*
Browse files Browse the repository at this point in the history
this helps in a lot of cases while designing algos that use zcash
compression, which is otherwise hard to distinguish from octets
  • Loading branch information
jaromil committed Jan 20, 2025
1 parent 934d10b commit 873f95c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/zen_ecp.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ const ecp* ecp_arg(lua_State *L, int n) {
// octet first class citizen
const octet *o = o_arg(L,n);
if(o) {
// check if input is zcash compressed
unsigned char m_byte = o->val[0] & 0xE0;
if(m_byte == 0x20 || m_byte == 0x60 || m_byte == 0xE0) {
zerror(L, "ECP arg %u is zcash compressed",n);
o_free(L,o);
return NULL;
}
res = malloc(sizeof(ecp));
res->totlen = (MODBYTES*2)+1;
_ecp_from_octet(res, o);
Expand Down
22 changes: 15 additions & 7 deletions src/zen_ecp2.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ ecp2* ecp2_new(lua_State *L) {

const ecp2* ecp2_arg(lua_State *L, int n) {
Z(L);
ecp2 *res;
void *ud = luaL_testudata(L, n, "zenroom.ecp2");
if(HEDLEY_UNLIKELY(ud==NULL)) {
zerror(L, "invalid ECP2 point in argument");
return NULL;
}
ecp2 *res = (ecp2*)ud;
res->ref++;
return(res);
if(ud) {
res = (ecp2*)ud;
res->ref++;
return(res);
}
const octet *o = o_arg(L,n);
if(!o) return NULL;
// check if input is zcash compressed
// TODO: use zcash compression by default
unsigned char m_byte = o->val[0] & 0xE0;
if(m_byte == 0x20 || m_byte == 0x60 || m_byte == 0xE0)
zerror(L, "ECP2 arg %u is zcash compressed",n);
o_free(L,o);
return NULL;
}

ecp2* ecp2_dup(lua_State *L, const ecp2* in) {
Expand Down

0 comments on commit 873f95c

Please sign in to comment.