2013-09-29 00:21:18 +04:00
|
|
|
/* j/5/shax.c
|
|
|
|
**
|
|
|
|
** This file is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
#include "../pit.h"
|
|
|
|
|
2014-04-21 01:51:35 +04:00
|
|
|
#if defined(U2_OS_osx)
|
|
|
|
#include <CommonCrypto/CommonDigest.h>
|
|
|
|
#else
|
2013-09-29 00:21:18 +04:00
|
|
|
#include <openssl/sha.h>
|
2014-04-21 01:51:35 +04:00
|
|
|
#endif
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
/* functions
|
|
|
|
*/
|
|
|
|
u2_weak // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mbc(Pt5, shax)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_atom a) // retain
|
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
c3_w met_w = u2_cr_met(3, a);
|
2014-04-02 04:47:01 +04:00
|
|
|
c3_y* fat_y = c3_malloc(met_w + 1);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_cr_bytes(0, met_w, fat_y, a);
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
c3_y dig_y[32];
|
2014-04-21 01:51:35 +04:00
|
|
|
#if defined(U2_OS_osx)
|
|
|
|
CC_SHA256_CTX ctx_h;
|
|
|
|
|
|
|
|
CC_SHA256_Init(&ctx_h);
|
|
|
|
CC_SHA256_Update(&ctx_h, fat_y, met_w);
|
|
|
|
CC_SHA256_Final(dig_y, &ctx_h);
|
|
|
|
#else
|
2013-09-29 00:21:18 +04:00
|
|
|
SHA256_CTX ctx_h;
|
|
|
|
|
|
|
|
SHA256_Init(&ctx_h);
|
|
|
|
SHA256_Update(&ctx_h, fat_y, met_w);
|
|
|
|
SHA256_Final(dig_y, &ctx_h);
|
2014-04-21 01:51:35 +04:00
|
|
|
#endif
|
2013-12-17 04:01:56 +04:00
|
|
|
free(fat_y);
|
2014-08-20 10:22:41 +04:00
|
|
|
return u2_ci_bytes(32, dig_y);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_weak // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mbc(Pt5, shal)(u2_atom a, // retain
|
2014-01-22 03:01:14 +04:00
|
|
|
u2_atom b) // retain
|
2014-01-21 06:10:40 +04:00
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
c3_assert(u2_so(u2_co_is_cat(a)));
|
2014-04-02 04:47:01 +04:00
|
|
|
c3_y* fat_y = c3_malloc(a + 1);
|
2014-01-21 06:10:40 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_cr_bytes(0, a, fat_y, b);
|
2014-01-21 06:10:40 +04:00
|
|
|
{
|
|
|
|
c3_y dig_y[64];
|
2014-04-21 01:51:35 +04:00
|
|
|
#if defined(U2_OS_osx)
|
|
|
|
CC_SHA512_CTX ctx_h;
|
|
|
|
|
|
|
|
CC_SHA512_Init(&ctx_h);
|
|
|
|
CC_SHA512_Update(&ctx_h, fat_y, a);
|
|
|
|
CC_SHA512_Final(dig_y, &ctx_h);
|
|
|
|
#else
|
2014-01-21 06:10:40 +04:00
|
|
|
SHA512_CTX ctx_h;
|
|
|
|
|
|
|
|
SHA512_Init(&ctx_h);
|
2014-01-22 03:01:14 +04:00
|
|
|
SHA512_Update(&ctx_h, fat_y, a);
|
2014-01-21 06:10:40 +04:00
|
|
|
SHA512_Final(dig_y, &ctx_h);
|
2014-04-21 01:51:35 +04:00
|
|
|
#endif
|
2014-01-21 06:10:40 +04:00
|
|
|
free(fat_y);
|
2014-08-20 10:22:41 +04:00
|
|
|
return u2_ci_bytes(64, dig_y);
|
2014-01-21 06:10:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_weak // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mbc(Pt5, shas)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_atom sal, // retain
|
|
|
|
u2_atom ruz) // retain
|
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun one = j2_mbc(Pt5, shax)(ruz);
|
|
|
|
u2_noun two = j2_mbc(Pt3, mix)(sal, one);
|
|
|
|
u2_noun tri = j2_mbc(Pt5, shax)(two);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
u2z(one); u2z(two); return tri;
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_weak // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mb(Pt5, shax)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun cor) // retain
|
|
|
|
{
|
|
|
|
u2_noun a;
|
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( (u2_none == (a = u2_cr_at(u2_cv_sam, cor))) ||
|
|
|
|
(u2_no == u2ud(a)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
return u2_cm_bail(c3__exit);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-20 10:22:41 +04:00
|
|
|
return j2_mbc(Pt5, shax)(a);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_weak // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mb(Pt5, shal)(u2_noun cor) // retain
|
2014-01-21 06:10:40 +04:00
|
|
|
{
|
2014-01-22 03:01:14 +04:00
|
|
|
u2_noun a, b;
|
2014-01-21 06:10:40 +04:00
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( (u2_none == (a = u2_cr_at(u2_cv_sam_2, cor))) ||
|
|
|
|
(u2_none == (b = u2_cr_at(u2_cv_sam_3, cor))) ||
|
|
|
|
(u2_no == u2ud(a)) ||
|
|
|
|
(u2_no == u2_co_is_cat(a)) ||
|
|
|
|
(u2_no == u2ud(b)) )
|
2014-01-21 06:10:40 +04:00
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
return u2_cm_bail(c3__exit);
|
2014-01-21 06:10:40 +04:00
|
|
|
} else {
|
2014-08-20 10:22:41 +04:00
|
|
|
return j2_mbc(Pt5, shal)(a, b);
|
2014-01-21 06:10:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_weak // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mb(Pt5, shas)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun cor) // retain
|
|
|
|
{
|
|
|
|
u2_noun sal, ruz;
|
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( (u2_none == (sal = u2_cr_at(u2_cv_sam_2, cor))) ||
|
|
|
|
(u2_none == (ruz = u2_cr_at(u2_cv_sam_3, cor))) ||
|
|
|
|
(u2_no == u2ud(sal)) ||
|
|
|
|
(u2_no == u2ud(ruz)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
return u2_cm_bail(c3__exit);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-20 10:22:41 +04:00
|
|
|
return j2_mbc(Pt5, shas)(sal, ruz);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u2_noun // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
_og_list(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun a, // retain
|
|
|
|
u2_noun b, // retain
|
|
|
|
u2_noun c) // retain
|
|
|
|
{
|
|
|
|
u2_noun l = u2_nul;
|
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( u2_ne(u2_co_is_cat(b)) ) {
|
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
while ( 0 != b ) {
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun x = j2_mbc(Pt3, mix)(a, c);
|
|
|
|
u2_noun y = j2_mbc(Pt3, mix)(b, x);
|
|
|
|
u2_noun d = j2_mbc(Pt5, shas)(c3_s4('o','g','-','b'), y);
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun m;
|
|
|
|
|
|
|
|
u2z(x); u2z(y);
|
|
|
|
|
|
|
|
if ( b < 256 ) {
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun e = j2_mbc(Pt3, end)(0, b, d);
|
2014-01-21 06:10:40 +04:00
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
u2z(d);
|
|
|
|
m = u2nc(b, e);
|
|
|
|
b = 0;
|
|
|
|
} else {
|
|
|
|
m = u2nc(256, d);
|
|
|
|
c = d;
|
|
|
|
|
|
|
|
b -= 256;
|
|
|
|
}
|
|
|
|
l = u2nc(m, l);
|
|
|
|
}
|
|
|
|
return u2_ckb_flop(l);
|
|
|
|
}
|
2014-01-21 06:10:40 +04:00
|
|
|
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun // produce
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mcc(Pt5, og, raw)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun a, // retain
|
|
|
|
u2_noun b) // retain
|
|
|
|
{
|
2014-08-20 10:22:41 +04:00
|
|
|
u2_noun x = j2_mbc(Pt3, mix)(b, a);
|
|
|
|
u2_noun c = j2_mbc(Pt5, shas)(c3_s4('o','g','-','a'), x);
|
|
|
|
u2_noun l = _og_list(a, b, c);
|
|
|
|
u2_noun r = j2_mbc(Pt3, can)(0, l);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
u2z(l);
|
|
|
|
u2z(c);
|
|
|
|
u2z(x);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
u2_weak // transfer
|
2014-08-20 10:22:41 +04:00
|
|
|
j2_mc(Pt5, og, raw)(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun cor) // retain
|
|
|
|
{
|
|
|
|
u2_noun a, b;
|
|
|
|
|
2014-08-20 10:22:41 +04:00
|
|
|
if ( u2_no == u2_cr_mean(cor, u2_cv_sam, &b, u2_cv_con_sam, &a, 0) ) {
|
|
|
|
return u2_cm_bail(c3__exit);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-20 10:22:41 +04:00
|
|
|
return j2_mcc(Pt5, og, raw)(a, b);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* structures
|
|
|
|
*/
|
2014-01-21 06:10:40 +04:00
|
|
|
u2_ho_jet
|
|
|
|
j2_mbj(Pt5, shax)[] = {
|
2013-09-29 00:21:18 +04:00
|
|
|
{ ".2", c3__lite, j2_mb(Pt5, shax), Tier5, u2_none, u2_none },
|
|
|
|
{ }
|
|
|
|
};
|
2014-01-21 06:10:40 +04:00
|
|
|
u2_ho_jet
|
2014-01-22 03:01:14 +04:00
|
|
|
j2_mbj(Pt5, shal)[] = {
|
2014-04-16 04:33:22 +04:00
|
|
|
{ ".2", c3__lite, j2_mb(Pt5, shal), Tier5, u2_none, u2_none },
|
2014-01-21 06:10:40 +04:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
u2_ho_jet
|
|
|
|
j2_mbj(Pt5, shas)[] = {
|
2013-09-29 00:21:18 +04:00
|
|
|
{ ".2", c3__lite, j2_mb(Pt5, shas), Tier5, u2_none, u2_none },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2014-01-21 06:10:40 +04:00
|
|
|
u2_ho_jet
|
2013-09-29 00:21:18 +04:00
|
|
|
j2_mcj(Pt5, og, raw)[] = {
|
|
|
|
{ ".2", c3__lite, j2_mc(Pt5, og, raw), Tier5, u2_none, u2_none },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2014-01-21 06:10:40 +04:00
|
|
|
u2_ho_driver
|
2013-09-29 00:21:18 +04:00
|
|
|
j2_mbd(Pt5, og)[] = {
|
|
|
|
{ j2_sc(Pt5, og, raw), j2_mcj(Pt5, og, raw), 0, 0, u2_none },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
u2_ho_driver
|
2014-01-21 06:10:40 +04:00
|
|
|
j2_db(Pt5, og) =
|
2013-09-29 00:21:18 +04:00
|
|
|
{ j2_sb(Pt5, og), 0, j2_mbd(Pt5, og), 0, u2_none };
|
|
|
|
|