mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-26 08:25:04 +03:00
Implement jet for ++sha-1:sha.
This commit is contained in:
parent
919780c570
commit
d969775d8f
@ -134,6 +134,7 @@
|
||||
u3_noun u3qe_shay(u3_atom, u3_atom);
|
||||
u3_noun u3qe_shas(u3_atom, u3_atom);
|
||||
u3_noun u3qe_shal(u3_atom, u3_atom);
|
||||
u3_noun u3qe_sha1(u3_atom, u3_atom);
|
||||
|
||||
u3_noun u3qeo_raw(u3_atom, u3_atom);
|
||||
|
||||
|
@ -145,6 +145,7 @@
|
||||
u3_noun u3we_shay(u3_noun);
|
||||
u3_noun u3we_shas(u3_noun);
|
||||
u3_noun u3we_shal(u3_noun);
|
||||
u3_noun u3we_sha1(u3_noun);
|
||||
|
||||
u3_noun u3weo_raw(u3_noun);
|
||||
|
||||
|
62
jets/e/sha1.c
Normal file
62
jets/e/sha1.c
Normal file
@ -0,0 +1,62 @@
|
||||
/* j/5/sha1.c
|
||||
**
|
||||
*/
|
||||
#include "all.h"
|
||||
|
||||
|
||||
#if defined(U3_OS_osx)
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#else
|
||||
#include <openssl/sha.h>
|
||||
#endif
|
||||
|
||||
/* functions
|
||||
*/
|
||||
|
||||
u3_noun
|
||||
u3qe_sha1(u3_atom wid,
|
||||
u3_atom dat)
|
||||
{
|
||||
c3_assert(_(u3a_is_cat(wid)));
|
||||
dat = u3qc_rev(3, wid, dat);
|
||||
|
||||
//NOTE XX fixme we shouldn't c3_malloc in inner road,
|
||||
// this is also done in other SHA jets
|
||||
c3_y* fat_y = c3_malloc(wid + 1);
|
||||
u3r_bytes(0, wid, fat_y, dat);
|
||||
{
|
||||
c3_y dig_y[32];
|
||||
#if defined(U3_OS_osx)
|
||||
CC_SHA1_CTX ctx_h;
|
||||
|
||||
CC_SHA1_Init(&ctx_h);
|
||||
CC_SHA1_Update(&ctx_h, fat_y, wid);
|
||||
CC_SHA1_Final(dig_y, &ctx_h);
|
||||
#else
|
||||
SHA1_CTX ctx_h;
|
||||
|
||||
SHA1_Init(&ctx_h);
|
||||
SHA1_Update(&ctx_h, fat_y, wid);
|
||||
SHA1_Final(dig_y, &ctx_h);
|
||||
#endif
|
||||
free(fat_y);
|
||||
u3z(dat);
|
||||
return u3kc_rev(3, 20, u3i_bytes(20, dig_y));
|
||||
}
|
||||
}
|
||||
|
||||
u3_noun
|
||||
u3we_sha1(u3_noun cor)
|
||||
{
|
||||
u3_noun wid, dat;
|
||||
|
||||
if ( (c3n == u3r_mean(cor, u3x_sam_2, &wid, u3x_sam_3, &dat, 0)) ||
|
||||
(c3n == u3ud(wid)) ||
|
||||
(c3n == u3a_is_cat(wid)) ||
|
||||
(c3n == u3ud(dat)) )
|
||||
{
|
||||
return u3m_bail(c3__exit);
|
||||
} else {
|
||||
return u3qe_sha1(wid, dat);
|
||||
}
|
||||
}
|
@ -446,6 +446,12 @@ static u3j_core _143_qua_d[] =
|
||||
{}
|
||||
};
|
||||
|
||||
static u3j_harm _143_tri__sha_sha1_a[] = {{".2", u3we_sha1}, {}};
|
||||
static u3j_core _143_tri__sha_d[] =
|
||||
{ { "sha1", _143_tri__sha_sha1_a },
|
||||
{}
|
||||
};
|
||||
|
||||
static u3j_harm _143_tri_shax_a[] = {{".2", u3we_shax}, {}};
|
||||
static u3j_harm _143_tri_shay_a[] = {{".2", u3we_shay}, {}};
|
||||
static u3j_harm _143_tri_shas_a[] = {{".2", u3we_shas}, {}};
|
||||
@ -460,6 +466,7 @@ static u3j_core _143_tri_d[] =
|
||||
{ "rq", 0, _143_tri__rq_d },
|
||||
{ "rh", 0, _143_tri__rh_d },
|
||||
{ "og", 0, _143_tri__og_d },
|
||||
{ "sha", 0, _143_tri__sha_d },
|
||||
{ "shax", _143_tri_shax_a },
|
||||
{ "shay", _143_tri_shay_a },
|
||||
{ "shas", _143_tri_shas_a },
|
||||
|
@ -118,6 +118,7 @@ jets_e_src = [
|
||||
'jets/e/rub.c',
|
||||
'jets/e/scr.c',
|
||||
'jets/e/shax.c',
|
||||
'jets/e/sha1.c',
|
||||
'jets/e/lore.c',
|
||||
'jets/e/loss.c',
|
||||
'jets/e/lune.c',
|
||||
|
Loading…
Reference in New Issue
Block a user