Merge branch 'jet-aes', remote-tracking branch 'dhaffey/burn-zeroing'

AES, Ed25519, and ++rep jets
Prevent ++burn:ut jet from zeroing non-constants
This commit is contained in:
Raymond Pasco 2016-08-10 15:00:51 -07:00
commit f3547e7ac4
10 changed files with 1217 additions and 29 deletions

View File

@ -218,6 +218,7 @@ J_C_OFILES=\
jets/c/po.o \
jets/c/pow.o \
jets/c/rap.o \
jets/c/rep.o \
jets/c/rip.o \
jets/c/rsh.o \
jets/c/sqt.o \
@ -243,6 +244,8 @@ J_D_OFILES=\
jets/d/by_dif.o
J_E_OFILES=\
jets/e/aes_ecb.o \
jets/e/aes_cbc.o \
jets/e/aesc.o \
jets/e/cue.o \
jets/e/fl.o \
@ -265,7 +268,8 @@ J_E_OFILES=\
J_E_OFILES_ED=\
jets/e/ed_puck.o \
jets/e/ed_sign.o \
jets/e/ed_veri.o
jets/e/ed_veri.o \
jets/e/ed_shar.o
J_F_OFILES=\
jets/f/al.o \

View File

@ -63,6 +63,7 @@
u3_noun u3qc_peg(u3_atom, u3_atom);
u3_noun u3qc_pow(u3_atom, u3_atom);
u3_noun u3qc_rap(u3_atom, u3_noun);
u3_noun u3qc_rep(u3_atom, u3_noun);
u3_noun u3qc_rip(u3_atom, u3_atom);
u3_noun u3qc_rsh(u3_atom, u3_atom, u3_atom);
u3_noun u3qc_sqt(u3_atom);
@ -103,6 +104,20 @@
u3_noun u3qe_rexp(u3_noun, u3_noun);
u3_noun u3qe_trip(u3_atom);
u3_noun u3qea_ecba_en(u3_atom, u3_atom);
u3_noun u3qea_ecba_de(u3_atom, u3_atom);
u3_noun u3qea_ecbb_en(u3_atom, u3_atom);
u3_noun u3qea_ecbb_de(u3_atom, u3_atom);
u3_noun u3qea_ecbc_en(u3_atom, u3_atom);
u3_noun u3qea_ecbc_de(u3_atom, u3_atom);
u3_noun u3qea_cbca_en(u3_atom, u3_atom, u3_atom);
u3_noun u3qea_cbca_de(u3_atom, u3_atom, u3_atom);
u3_noun u3qea_cbcb_en(u3_atom, u3_atom, u3_atom);
u3_noun u3qea_cbcb_de(u3_atom, u3_atom, u3_atom);
u3_noun u3qea_cbcc_en(u3_atom, u3_atom, u3_atom);
u3_noun u3qea_cbcc_de(u3_atom, u3_atom, u3_atom);
u3_noun u3qea_de(u3_atom, u3_atom);
u3_noun u3qea_en(u3_atom, u3_atom);

View File

@ -63,6 +63,7 @@
u3_noun u3wc_peg(u3_noun);
u3_noun u3wc_pow(u3_noun);
u3_noun u3wc_rap(u3_noun);
u3_noun u3wc_rep(u3_noun);
u3_noun u3wc_rip(u3_noun);
u3_noun u3wc_rsh(u3_noun);
u3_noun u3wc_sqt(u3_noun);
@ -115,6 +116,20 @@
u3_noun u3we_pose(u3_noun);
u3_noun u3we_sfix(u3_noun);
u3_noun u3wea_ecba_en(u3_noun);
u3_noun u3wea_ecba_de(u3_noun);
u3_noun u3wea_ecbb_en(u3_noun);
u3_noun u3wea_ecbb_de(u3_noun);
u3_noun u3wea_ecbc_en(u3_noun);
u3_noun u3wea_ecbc_de(u3_noun);
u3_noun u3wea_cbca_en(u3_noun);
u3_noun u3wea_cbca_de(u3_noun);
u3_noun u3wea_cbcb_en(u3_noun);
u3_noun u3wea_cbcb_de(u3_noun);
u3_noun u3wea_cbcc_en(u3_noun);
u3_noun u3wea_cbcc_de(u3_noun);
u3_noun u3wea_de(u3_noun);
u3_noun u3wea_en(u3_noun);
@ -133,6 +148,7 @@
u3_noun u3wee_puck(u3_noun);
u3_noun u3wee_sign(u3_noun);
u3_noun u3wee_veri(u3_noun);
u3_noun u3wee_shar(u3_noun);
u3_noun u3we_bend_fun(u3_noun);
u3_noun u3we_cold_fun(u3_noun);

87
jets/c/rep.c Normal file
View File

@ -0,0 +1,87 @@
/* j/3/rep.c
**
*/
#include "all.h"
/* functions
*/
u3_noun
u3qc_rep(u3_atom a,
u3_noun b)
{
if ( !_(u3a_is_cat(a)) || (a >= 32) ) {
return u3m_bail(c3__exit);
}
else {
c3_g a_g = a;
c3_w tot_w = 0;
c3_w* sal_w;
/* Measure and validate the slab required.
*/
{
u3_noun cab = b;
while ( 1 ) {
u3_noun h_cab;
c3_w len_w;
if ( 0 == cab ) {
break;
}
else if ( c3n == u3du(cab) ) {
return u3m_bail(c3__exit);
}
else if ( c3n == u3ud(h_cab = u3h(cab)) ) {
return u3m_bail(c3__exit);
}
else if ( (tot_w + (len_w = u3r_met(a_g, h_cab))) < tot_w ) {
return u3m_bail(c3__fail);
}
tot_w++;
cab = u3t(cab);
}
if ( 0 == tot_w ) {
return 0;
}
if ( 0 == (sal_w = u3a_slaq(a_g, tot_w)) ) {
return u3m_bail(c3__fail);
}
}
/* Chop the list atoms in.
*/
{
u3_noun cab = b;
c3_w pos_w = 0;
while ( 0 != cab ) {
u3_noun h_cab = u3h(cab);
u3r_chop(a_g, 0, 1, pos_w, sal_w, h_cab);
pos_w++;
cab = u3t(cab);
}
}
// return u3a_moot(sal_w);
return u3a_malt(sal_w);
}
}
u3_noun
u3wc_rep(u3_noun cor)
{
u3_noun a, b;
if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ||
(c3n == u3ud(a)) )
{
return u3m_bail(c3__exit);
} else {
u3_noun pro;
pro = u3qc_rep(a, b);
return pro;
}
}

548
jets/e/aes_cbc.c Normal file
View File

@ -0,0 +1,548 @@
/* j/5/aes_cbc.c
**
*/
#include "all.h"
#include <openssl/aes.h>
/* functions
*/
u3_noun
u3qea_cbca_en(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[16];
c3_y iv_y[16];
c3_w len_msg_w;
c3_w len_out_w;
c3_y *msg_y;
c3_y *out_y;
u3_atom out;
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 16);
c3_assert(u3r_met(3, iv) <= 16);
len_msg_w = u3r_met(3, msg);
len_out_w = (len_msg_w % 16) == 0 ? len_msg_w : len_msg_w + (16 - (len_msg_w % 16));
len_msg_w = len_out_w;
msg_y = u3a_malloc(len_msg_w);
out_y = u3a_malloc(len_out_w);
{
int i = 15;
do {
key_y[i] = u3r_byte(15-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
iv_y[i] = u3r_byte(15-i, iv);
i--;
} while (i >= 0);
}
{
int i = len_msg_w - 1;
do {
msg_y[i] = u3r_byte((len_msg_w - 1)-i, msg);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_encrypt_key(key_y, 128, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_cbc_encrypt(msg_y, out_y, len_msg_w, &key_u, iv_y, AES_ENCRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = len_out_w - 1;
int j = 0;
c3_y tmp;
do {
tmp = out_y[i];
out_y[i] = out_y[j];
out_y[j] = tmp;
i--; j++;
} while (i > j);
}
out = u3i_bytes(len_out_w, out_y);
u3a_free(msg_y);
u3a_free(out_y);
return out;
}
u3_noun
u3wea_cbca_en(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_cbca_en(a, b, c);
}
}
u3_noun
u3qea_cbca_de(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[16];
c3_y iv_y[16];
c3_w len_msg_w;
c3_w len_out_w;
c3_y *msg_y;
c3_y *out_y;
u3_atom out;
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 16);
c3_assert(u3r_met(3, iv) <= 16);
len_msg_w = u3r_met(3, msg);
len_out_w = (len_msg_w % 16) == 0 ? len_msg_w : len_msg_w + (16 - (len_msg_w % 16));
len_msg_w = len_out_w;
msg_y = u3a_malloc(len_msg_w);
out_y = u3a_malloc(len_out_w);
{
int i = 15;
do {
key_y[i] = u3r_byte(15-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
iv_y[i] = u3r_byte(15-i, iv);
i--;
} while (i >= 0);
}
{
int i = len_msg_w - 1;
do {
msg_y[i] = u3r_byte((len_msg_w - 1)-i, msg);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_decrypt_key(key_y, 128, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_cbc_encrypt(msg_y, out_y, len_msg_w, &key_u, iv_y, AES_DECRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = len_out_w - 1;
int j = 0;
c3_y tmp;
do {
tmp = out_y[i];
out_y[i] = out_y[j];
out_y[j] = tmp;
i--; j++;
} while (i > j);
}
out = u3i_bytes(len_out_w, out_y);
u3a_free(msg_y);
u3a_free(out_y);
return out;
}
u3_noun
u3wea_cbca_de(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_cbca_de(a, b, c);
}
}
u3_noun
u3qea_cbcb_en(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[24];
c3_y iv_y[16];
c3_w len_msg_w;
c3_w len_out_w;
c3_y *msg_y;
c3_y *out_y;
u3_atom out;
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 24);
c3_assert(u3r_met(3, iv) <= 16);
len_msg_w = u3r_met(3, msg);
len_out_w = (len_msg_w % 16) == 0 ? len_msg_w : len_msg_w + (16 - (len_msg_w % 16));
len_msg_w = len_out_w;
msg_y = u3a_malloc(len_msg_w);
out_y = u3a_malloc(len_out_w);
{
int i = 23;
do {
key_y[i] = u3r_byte(23-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
iv_y[i] = u3r_byte(15-i, iv);
i--;
} while (i >= 0);
}
{
int i = len_msg_w - 1;
do {
msg_y[i] = u3r_byte((len_msg_w - 1)-i, msg);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_encrypt_key(key_y, 192, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_cbc_encrypt(msg_y, out_y, len_msg_w, &key_u, iv_y, AES_ENCRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = len_out_w - 1;
int j = 0;
c3_y tmp;
do {
tmp = out_y[i];
out_y[i] = out_y[j];
out_y[j] = tmp;
i--; j++;
} while (i > j);
}
out = u3i_bytes(len_out_w, out_y);
u3a_free(msg_y);
u3a_free(out_y);
return out;
}
u3_noun
u3wea_cbcb_en(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_cbcb_en(a, b, c);
}
}
u3_noun
u3qea_cbcb_de(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[24];
c3_y iv_y[16];
c3_w len_msg_w;
c3_w len_out_w;
c3_y *msg_y;
c3_y *out_y;
u3_atom out;
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 24);
c3_assert(u3r_met(3, iv) <= 16);
len_msg_w = u3r_met(3, msg);
len_out_w = (len_msg_w % 16) == 0 ? len_msg_w : len_msg_w + (16 - (len_msg_w % 16));
len_msg_w = len_out_w;
msg_y = u3a_malloc(len_msg_w);
out_y = u3a_malloc(len_out_w);
{
int i = 23;
do {
key_y[i] = u3r_byte(23-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
iv_y[i] = u3r_byte(15-i, iv);
i--;
} while (i >= 0);
}
{
int i = len_msg_w - 1;
do {
msg_y[i] = u3r_byte((len_msg_w - 1)-i, msg);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_decrypt_key(key_y, 192, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_cbc_encrypt(msg_y, out_y, len_msg_w, &key_u, iv_y, AES_DECRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = len_out_w - 1;
int j = 0;
c3_y tmp;
do {
tmp = out_y[i];
out_y[i] = out_y[j];
out_y[j] = tmp;
i--; j++;
} while (i > j);
}
out = u3i_bytes(len_out_w, out_y);
u3a_free(msg_y);
u3a_free(out_y);
return out;
}
u3_noun
u3wea_cbcb_de(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_cbcb_de(a, b, c);
}
}
u3_noun
u3qea_cbcc_en(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[32];
c3_y iv_y[16];
c3_w len_msg_w;
c3_w len_out_w;
c3_y *msg_y;
c3_y *out_y;
u3_atom out;
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 32);
c3_assert(u3r_met(3, iv) <= 16);
len_msg_w = u3r_met(3, msg);
len_out_w = (len_msg_w % 16) == 0 ? len_msg_w : len_msg_w + (16 - (len_msg_w % 16));
len_msg_w = len_out_w;
msg_y = u3a_malloc(len_msg_w);
out_y = u3a_malloc(len_out_w);
{
int i = 31;
do {
key_y[i] = u3r_byte(31-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
iv_y[i] = u3r_byte(15-i, iv);
i--;
} while (i >= 0);
}
{
int i = len_msg_w - 1;
do {
msg_y[i] = u3r_byte((len_msg_w - 1)-i, msg);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_encrypt_key(key_y, 256, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_cbc_encrypt(msg_y, out_y, len_msg_w, &key_u, iv_y, AES_ENCRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = len_out_w - 1;
int j = 0;
c3_y tmp;
do {
tmp = out_y[i];
out_y[i] = out_y[j];
out_y[j] = tmp;
i--; j++;
} while (i > j);
}
out = u3i_bytes(len_out_w, out_y);
u3a_free(msg_y);
u3a_free(out_y);
return out;
}
u3_noun
u3wea_cbcc_en(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_cbcc_en(a, b, c);
}
}
u3_noun
u3qea_cbcc_de(u3_atom key,
u3_atom iv,
u3_atom msg)
{
c3_y key_y[32];
c3_y iv_y[16];
c3_w len_msg_w;
c3_w len_out_w;
c3_y *msg_y;
c3_y *out_y;
u3_atom out;
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 32);
c3_assert(u3r_met(3, iv) <= 16);
len_msg_w = u3r_met(3, msg);
len_out_w = (len_msg_w % 16) == 0 ? len_msg_w : len_msg_w + (16 - (len_msg_w % 16));
len_msg_w = len_out_w;
msg_y = u3a_malloc(len_msg_w);
out_y = u3a_malloc(len_out_w);
{
int i = 31;
do {
key_y[i] = u3r_byte(31-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
iv_y[i] = u3r_byte(15-i, iv);
i--;
} while (i >= 0);
}
{
int i = len_msg_w - 1;
do {
msg_y[i] = u3r_byte((len_msg_w - 1)-i, msg);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_decrypt_key(key_y, 256, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_cbc_encrypt(msg_y, out_y, len_msg_w, &key_u, iv_y, AES_DECRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = len_out_w - 1;
int j = 0;
c3_y tmp;
do {
tmp = out_y[i];
out_y[i] = out_y[j];
out_y[j] = tmp;
i--; j++;
} while (i > j);
}
out = u3i_bytes(len_out_w, out_y);
u3a_free(msg_y);
u3a_free(out_y);
return out;
}
u3_noun
u3wea_cbcc_de(u3_noun cor)
{
u3_noun a, b, c;
if ( c3n == u3r_mean(cor, u3x_sam, &c, 60, &a, 61, &b, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_cbcc_de(a, b, c);
}
}

407
jets/e/aes_ecb.c Normal file
View File

@ -0,0 +1,407 @@
/* j/5/aes_ecb.c
**
*/
#include "all.h"
#include <openssl/aes.h>
/* functions
*/
u3_noun
u3qea_ecba_en(u3_atom key,
u3_atom blk)
{
c3_y key_y[16];
c3_y blk_y[16];
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 16);
c3_assert(u3r_met(3, blk) <= 16);
{
int i = 15;
do {
key_y[i] = u3r_byte(15-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
blk_y[i] = u3r_byte(15-i, blk);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_encrypt_key(key_y, 128, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_ecb_encrypt(blk_y, blk_y, &key_u, AES_ENCRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = 15;
int j = 0;
c3_y tmp;
do {
tmp = blk_y[i];
blk_y[i] = blk_y[j];
blk_y[j] = tmp;
i--; j++;
} while (i > j);
}
return u3i_bytes(16, blk_y);
}
u3_noun
u3wea_ecba_en(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_ecba_en(a, b);
}
}
u3_noun
u3qea_ecba_de(u3_atom key,
u3_atom blk)
{
c3_y key_y[16];
c3_y blk_y[16];
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 16);
c3_assert(u3r_met(3, blk) <= 16);
{
int i = 15;
do {
key_y[i] = u3r_byte(15-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
blk_y[i] = u3r_byte(15-i, blk);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_decrypt_key(key_y, 128, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_ecb_encrypt(blk_y, blk_y, &key_u, AES_DECRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = 15;
int j = 0;
c3_y tmp;
do {
tmp = blk_y[i];
blk_y[i] = blk_y[j];
blk_y[j] = tmp;
i--; j++;
} while (i > j);
}
return u3i_bytes(16, blk_y);
}
u3_noun
u3wea_ecba_de(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_ecba_de(a, b);
}
}
u3_noun
u3qea_ecbb_en(u3_atom key,
u3_atom blk)
{
c3_y key_y[24];
c3_y blk_y[16];
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 24);
c3_assert(u3r_met(3, blk) <= 16);
{
int i = 23;
do {
key_y[i] = u3r_byte(23-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
blk_y[i] = u3r_byte(15-i, blk);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_encrypt_key(key_y, 192, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_ecb_encrypt(blk_y, blk_y, &key_u, AES_ENCRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = 15;
int j = 0;
c3_y tmp;
do {
tmp = blk_y[i];
blk_y[i] = blk_y[j];
blk_y[j] = tmp;
i--; j++;
} while (i > j);
}
return u3i_bytes(16, blk_y);
}
u3_noun
u3wea_ecbb_en(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_ecbb_en(a, b);
}
}
u3_noun
u3qea_ecbb_de(u3_atom key,
u3_atom blk)
{
c3_y key_y[24];
c3_y blk_y[16];
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 24);
c3_assert(u3r_met(3, blk) <= 16);
{
int i = 23;
do {
key_y[i] = u3r_byte(23-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
blk_y[i] = u3r_byte(15-i, blk);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_decrypt_key(key_y, 192, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_ecb_encrypt(blk_y, blk_y, &key_u, AES_DECRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = 15;
int j = 0;
c3_y tmp;
do {
tmp = blk_y[i];
blk_y[i] = blk_y[j];
blk_y[j] = tmp;
i--; j++;
} while (i > j);
}
return u3i_bytes(16, blk_y);
}
u3_noun
u3wea_ecbb_de(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_ecbb_de(a, b);
}
}
u3_noun
u3qea_ecbc_en(u3_atom key,
u3_atom blk)
{
c3_y key_y[32];
c3_y blk_y[16];
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 32);
c3_assert(u3r_met(3, blk) <= 16);
{
int i = 31;
do {
key_y[i] = u3r_byte(31-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
blk_y[i] = u3r_byte(15-i, blk);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_encrypt_key(key_y, 256, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_ecb_encrypt(blk_y, blk_y, &key_u, AES_ENCRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = 15;
int j = 0;
c3_y tmp;
do {
tmp = blk_y[i];
blk_y[i] = blk_y[j];
blk_y[j] = tmp;
i--; j++;
} while (i > j);
}
return u3i_bytes(16, blk_y);
}
u3_noun
u3wea_ecbc_en(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_ecbc_en(a, b);
}
}
u3_noun
u3qea_ecbc_de(u3_atom key,
u3_atom blk)
{
c3_y key_y[32];
c3_y blk_y[16];
AES_KEY key_u;
c3_assert(u3r_met(3, key) <= 32);
c3_assert(u3r_met(3, blk) <= 16);
{
int i = 31;
do {
key_y[i] = u3r_byte(31-i, key);
i--;
} while (i >= 0);
}
{
int i = 15;
do {
blk_y[i] = u3r_byte(15-i, blk);
i--;
} while (i >= 0);
}
if ( 0 != AES_set_decrypt_key(key_y, 256, &key_u) ) {
return u3m_bail(c3__exit);
}
else {
AES_ecb_encrypt(blk_y, blk_y, &key_u, AES_DECRYPT);
}
/* array reverse - we can write backwards u3i_bytes *
* in the unlikely event that this becomes a problem */
{
int i = 15;
int j = 0;
c3_y tmp;
do {
tmp = blk_y[i];
blk_y[i] = blk_y[j];
blk_y[j] = tmp;
i--; j++;
} while (i > j);
}
return u3i_bytes(16, blk_y);
}
u3_noun
u3wea_ecbc_de(u3_noun cor)
{
u3_noun a, b;
if ( c3n == u3r_mean(cor, u3x_sam, &b, u3x_con_sam, &a, 0) ||
c3n == u3ud(a) ||
c3n == u3ud(b) ) {
return u3m_bail(c3__exit);
} else {
return u3qea_ecbc_de(a, b);
}
}

47
jets/e/ed_shar.c Normal file
View File

@ -0,0 +1,47 @@
/* j/5/shar.c
**
*/
#include "all.h"
#include <ed25519.h>
u3_noun
u3qee_shar(u3_atom pub, u3_atom sek)
{
c3_y pub_y[32], sek_y[32], self_y[32], exp_y[64], shr_y[32];
c3_w met_pub_w, met_sek_w;
met_pub_w = u3r_met(3, pub);
met_sek_w = u3r_met(3, sek);
if ( (met_pub_w > 32) || (met_sek_w > 32) ) {
return u3m_bail(c3__exit);
}
u3r_bytes(0, 32, pub_y, pub);
u3r_bytes(0, 32, sek_y, sek);
memset(self_y, 0, 32);
memset(exp_y, 0, 64);
memset(shr_y, 0, 32);
ed25519_create_keypair(self_y, exp_y, sek_y);
ed25519_key_exchange(shr_y, pub_y, exp_y);
return u3i_bytes(32, shr_y);
}
u3_noun
u3wee_shar(u3_noun cor)
{
u3_noun pub, sek;
if ( (c3n == u3r_mean(cor, u3x_sam_2, &pub, u3x_sam_3, &sek, 0)) ||
(c3n == u3ud(pub)) ||
(c3n == u3ud(sek)) )
{
return u3m_bail(c3__exit);
} else {
return u3qee_shar(pub, sek);
}
}

View File

@ -58,7 +58,7 @@
if ( c3n == u3du(sut) ) switch ( sut ) {
default: return u3m_bail(c3__fail);
case c3__noun: return u3nc(u3_nul, 0);
case c3__noun: return 0;
case c3__void: {
return u3_nul;
}
@ -68,11 +68,7 @@
case c3__atom: u3x_cell(u3t(sut), &p_sut, &q_sut);
{
if ( c3y == u3du(q_sut) ) {
return u3nc(u3_nul, u3k(u3t(q_sut)));
} else {
return u3nc(u3_nul, 0);
}
return u3k(q_sut);
}
case c3__cell: u3x_cell(u3t(sut), &p_sut, &q_sut);
{
@ -148,17 +144,7 @@
_cqfu_burn(u3_noun van,
u3_noun sut)
{
u3_noun unt = _burn_in(van, sut, u3_nul);
if ( u3_nul == unt ) {
return u3m_error("burn");
}
else {
u3_noun ret = u3k(u3t(unt));
u3z(unt);
return ret;
}
return _burn_in(van, sut, u3_nul);
}
u3_noun

View File

@ -98,7 +98,7 @@
{
if ( 0 == u3h(nug) ) {
return u3k(u3t(nug));
}
}
else if ( 10 == u3h(nug) ) {
return _mint_coke(u3t(u3t(nug)));
}
@ -239,10 +239,10 @@
u3_noun von = u3i_molt(u3k(van), u3x_sam, u3k(sut), 0);
u3_noun gat = u3j_hook(von, "emin");
return u3n_kick_on(u3i_molt(gat,
u3x_sam_2,
u3k(gol),
u3x_sam_6,
return u3n_kick_on(u3i_molt(gat,
u3x_sam_2,
u3k(gol),
u3x_sam_6,
u3k(hyp),
u3x_sam_7,
u3k(rig),
@ -333,8 +333,8 @@
{
if ( (c3n == _mint_vet(van))
|| ((c3y == u3du(gen)) &&
((c3__zpfs == u3h(gen)) ||
(c3__lost == u3h(gen)) ||
((c3__zpfs == u3h(gen)) ||
(c3__lost == u3h(gen)) ||
(c3__fail == u3h(gen)) ||
(c3__zpzp == u3h(gen)))) )
{
@ -501,11 +501,11 @@
u3_noun nog = u3nc(c3__bunt, u3k(p_gen));
u3_noun nef = _mint_in(van, sut, gol, nog);
u3_noun viz = _mint_in(van, sut, c3__noun, q_gen);
ret = u3nc(u3k(u3h(nef)),
ret = u3nc(u3k(u3h(nef)),
u3nt(11, u3nc(1, u3nc(151, u3k(u3h(nef)))), u3k(u3t(viz))));
u3z(viz);
u3z(viz);
u3z(nef);
u3z(nog);
return ret;
@ -615,7 +615,12 @@
{
u3_noun cag = u3qfu_burn(van, sut);
u3_noun wim = u3n_nock_an(cag, u3k(q_nef));
u3_noun wim;
if ( 0 == cag ) {
wim = u3nc(2, 0);
} else {
wim = u3n_nock_an(u3k(u3t(cag)), u3k(q_nef));
}
if ( 0 == u3h(wim) ) {
fom = u3nc(1, u3k(u3t(wim)));

View File

@ -58,6 +58,7 @@ static u3j_harm _mood__hoon_muk_a[] = {{".2", u3wc_muk, c3y}, {}};
static u3j_harm _mood__hoon_peg_a[] = {{".2", u3wc_peg, c3y}, {}};
static u3j_harm _mood__hoon_pow_a[] = {{".2", u3wc_pow, c3y}, {}};
static u3j_harm _mood__hoon_rap_a[] = {{".2", u3wc_rap, c3y}, {}};
static u3j_harm _mood__hoon_rep_a[] = {{".2", u3wc_rep, c3y}, {}};
static u3j_harm _mood__hoon_rip_a[] = {{".2", u3wc_rip, c3y}, {}};
static u3j_harm _mood__hoon_rsh_a[] = {{".2", u3wc_rsh, c3y}, {}};
static u3j_harm _mood__hoon_sqt_a[] = {{".2", u3wc_sqt, c3y}, {}};
@ -299,10 +300,13 @@ static u3j_core _mood__hoon__rq_d[] =
static u3j_harm _mood__hoon__coed__ed_puck_a[] = {{".2", u3wee_puck}, {}};
static u3j_harm _mood__hoon__coed__ed_sign_a[] = {{".2", u3wee_sign}, {}};
static u3j_harm _mood__hoon__coed__ed_veri_a[] = {{".2", u3wee_veri}, {}};
static u3j_harm _mood__hoon__coed__ed_shar_a[] = {{".2", u3wee_shar}, {}};
static u3j_core _mood__hoon__coed__ed_d[] =
{ { "sign", _mood__hoon__coed__ed_sign_a },
{ "puck", _mood__hoon__coed__ed_puck_a },
{ "veri", _mood__hoon__coed__ed_veri_a },
{ "shar", _mood__hoon__coed__ed_shar_a },
{}
};
static u3j_core _mood__hoon__coed_d[] =
@ -408,8 +412,76 @@ static u3j_core _down_d[] =
{}
};
static u3j_harm _zuse__aes_ecba_en_a[] = {{".2", u3wea_ecba_en}, {}};
static u3j_harm _zuse__aes_ecba_de_a[] = {{".2", u3wea_ecba_de}, {}};
static u3j_harm _zuse__aes_ecbb_en_a[] = {{".2", u3wea_ecbb_en}, {}};
static u3j_harm _zuse__aes_ecbb_de_a[] = {{".2", u3wea_ecbb_de}, {}};
static u3j_harm _zuse__aes_ecbc_en_a[] = {{".2", u3wea_ecbc_en}, {}};
static u3j_harm _zuse__aes_ecbc_de_a[] = {{".2", u3wea_ecbc_de}, {}};
static u3j_harm _zuse__aes_cbca_en_a[] = {{".2", u3wea_cbca_en}, {}};
static u3j_harm _zuse__aes_cbca_de_a[] = {{".2", u3wea_cbca_de}, {}};
static u3j_harm _zuse__aes_cbcb_en_a[] = {{".2", u3wea_cbcb_en}, {}};
static u3j_harm _zuse__aes_cbcb_de_a[] = {{".2", u3wea_cbcb_de}, {}};
static u3j_harm _zuse__aes_cbcc_en_a[] = {{".2", u3wea_cbcc_en}, {}};
static u3j_harm _zuse__aes_cbcc_de_a[] = {{".2", u3wea_cbcc_de}, {}};
static u3j_core _zuse__aes_ecba_d[] =
{ { "en", _zuse__aes_ecba_en_a },
{ "de", _zuse__aes_ecba_de_a },
{}
};
static u3j_core _zuse__aes_ecbb_d[] =
{ { "en", _zuse__aes_ecbb_en_a },
{ "de", _zuse__aes_ecbb_de_a },
{}
};
static u3j_core _zuse__aes_ecbc_d[] =
{ { "en", _zuse__aes_ecbc_en_a },
{ "de", _zuse__aes_ecbc_de_a },
{}
};
static u3j_core _zuse__aes_cbca_d[] =
{ { "en", _zuse__aes_cbca_en_a },
{ "de", _zuse__aes_cbca_de_a },
{}
};
static u3j_core _zuse__aes_cbcb_d[] =
{ { "en", _zuse__aes_cbcb_en_a },
{ "de", _zuse__aes_cbcb_de_a },
{}
};
static u3j_core _zuse__aes_cbcc_d[] =
{ { "en", _zuse__aes_cbcc_en_a },
{ "de", _zuse__aes_cbcc_de_a },
{}
};
static u3j_core _zuse__aes_d[] =
{ { "ecba", 0, _zuse__aes_ecba_d },
{ "ecbb", 0, _zuse__aes_ecbb_d },
{ "ecbc", 0, _zuse__aes_ecbc_d },
{ "cbca", 0, _zuse__aes_cbca_d },
{ "cbcb", 0, _zuse__aes_cbcb_d },
{ "cbcc", 0, _zuse__aes_cbcc_d },
{}
};
/*
static u3j_core _zuse_d[] =
{ { "aes", 0, _zuse__aes_d },
{}
};
*/
static u3j_core _arvo_d[] =
{ { "down", 0, _down_d },
{ "aes", 0, _zuse__aes_d },
{}
};
@ -469,6 +541,7 @@ static u3j_core _mood__hoon_d[] =
{ "peg", _mood__hoon_peg_a },
{ "pow", _mood__hoon_pow_a },
{ "rap", _mood__hoon_rap_a },
{ "rep", _mood__hoon_rep_a },
{ "rip", _mood__hoon_rip_a },
{ "rsh", _mood__hoon_rsh_a },
{ "sqt", _mood__hoon_sqt_a },