From d0b48313deacade1373b0aa395dbbaba74524190 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Fri, 9 Jan 2015 17:11:43 -0500 Subject: [PATCH 01/24] waypoint --- j/e/lore.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/j/e/lore.c b/j/e/lore.c index 5d4270cfe..a609ac561 100644 --- a/j/e/lore.c +++ b/j/e/lore.c @@ -20,7 +20,7 @@ } else { meg_w = 0; - c3_y byt_y; + c3_y byt_y; while ( 1 ) { byt_y = u3r_byte(pos_w + meg_w, lub); @@ -30,8 +30,8 @@ } if ((byt_y == 0) && ((pos_w + meg_w + 1) < len_w)) { - return u3m_bail(c3__exit); - } + return u3m_bail(c3__exit); + } { c3_y* byts_y = alloca(meg_w); From 94138294d03b5492b11d564f6b2fdf2f685ec377 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Tue, 13 Jan 2015 20:58:25 -0500 Subject: [PATCH 02/24] boots now (sort of) --- i/c/motes.h | 2 ++ v/unix.c | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/i/c/motes.h b/i/c/motes.h index 5c86c8e81..f88680ea9 100644 --- a/i/c/motes.h +++ b/i/c/motes.h @@ -666,6 +666,7 @@ # define c3__met c3_s3('m','e','t') # define c3__meta c3_s4('m','e','t','a') # define c3__mill c3_s4('m','i','l','l') +# define c3__mime c3_s4('m','i','m','e') # define c3__mine c3_s4('m','i','n','e') # define c3__mint c3_s4('m','i','n','t') # define c3__mirt c3_s4('m','i','r','t') @@ -1005,6 +1006,7 @@ # define c3__tank c3_s4('t','a','n','k') # define c3__tap c3_s3('t','a','p') # define c3__tarn c3_s4('t','a','r','n') +# define c3__tas c3_s3('t','a','s') # define c3__tash c3_s4('t','a','s','h') # define c3__teal c3_s4('t','e','a','l') # define c3__teck c3_s4('t','e','c','k') diff --git a/v/unix.c b/v/unix.c index a66ed8e6e..cb0c5a5b8 100644 --- a/v/unix.c +++ b/v/unix.c @@ -631,7 +631,7 @@ _unix_load(c3_c* pax_c) return 0; } fln_w = buf_u.st_size; - pad_y = c3_malloc(buf_u.st_size); + pad_y = c3_malloc(fln_w); red_w = read(fid_i, pad_y, fln_w); close(fid_i); @@ -642,10 +642,24 @@ _unix_load(c3_c* pax_c) return 0; } else { - u3_noun pad = u3i_bytes(fln_w, (c3_y *)pad_y); + // -:!>(*[[@tas @tas ~] @ud @]) + u3_noun typ = u3nt(c3__cell, + u3nt(c3__cell, + u3nc(c3__atom, c3__tas), + u3nt(c3__cell, + u3nc(c3__atom, c3__tas), + u3nt(c3__cube, + u3_nul, + u3nc(c3__atom, 'n')))), + u3nt(c3__cell, + u3nc(c3__atom, c3__ud), + u3nc(c3__atom, u3_nul))); + u3_noun nam = u3nt(c3__text, u3i_string("plain"), u3_nul); + u3_noun pad = u3nt(nam, fln_w, u3i_bytes(fln_w, (c3_y *)pad_y)); + u3_noun cay = u3nt(c3__mime, typ, pad); free(pad_y); - return pad; + return cay; } } @@ -683,12 +697,15 @@ _unix_save(c3_c* pax_c, u3_atom oat) static u3_noun _unix_file_load(u3_ufil* fil_u) { - u3_noun raw = _unix_load(fil_u->pax_c); + return _unix_load(fil_u->pax_c); +#if 0 if ( (0 == raw) || ('^' != fil_u->dot_c[1]) ) { return raw; } + else return u3ke_cue(raw); +#endif } From ba4f951dfd8632831d7d6f079061b906b6287151 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Wed, 14 Jan 2015 19:01:59 -0500 Subject: [PATCH 03/24] boots to terminal, then hangs --- v/unix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v/unix.c b/v/unix.c index cb0c5a5b8..762758eaa 100644 --- a/v/unix.c +++ b/v/unix.c @@ -1005,9 +1005,9 @@ _unix_desk_sync_into(u3_noun who, xun = _unix_dir_ankh(dir_u); bur = _unix_desk_peek(hox, u3k(syd), u3k(u3A->wen)); - if ( (c3n == u3r_sing(u3h(xun), u3h(bur)))) + if ( (c3n == u3r_sing(u3h(xun), u3h(u3t(bur))))) { - doz = u3dc("cost", xun, bur); + doz = u3dc("cost", xun, u3t(bur)); pax = u3nq(u3_blip, c3__sync, u3k(u3A->sen), u3_nul); fav = u3nq(c3__into, who, syd, u3nc(c3y, doz)); From 938e01bc000f7faba4a23abd31ea9efa35d3d027 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Thu, 15 Jan 2015 15:57:13 -0500 Subject: [PATCH 04/24] waypoint --- v/unix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v/unix.c b/v/unix.c index 762758eaa..d9461da8e 100644 --- a/v/unix.c +++ b/v/unix.c @@ -856,7 +856,7 @@ _unix_dir_ankh(u3_udir* dir_u) continue; } u3_noun baw = _unix_file_load(fil_u); - u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(baw)), baw); + u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(u3t(u3t(baw)))), baw); u3z(dur); pam = _unix_dir_ankh_file(pam, u3k(u3t(wib)), baw, woz); u3z(wib); @@ -866,7 +866,7 @@ _unix_dir_ankh(u3_udir* dir_u) for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { u3_noun wib = _unix_file_name(fil_u); u3_noun baw = _unix_file_load(fil_u); - u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(baw)), baw); + u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(u3t(u3t(baw)))), baw); pam = _unix_dir_ankh_file(pam, wib, baw, woz); } return u3do("cosh", u3nt(0, u3_nul, pam)); From 75c66474757b94d6704995f9a907a12e6b03816c Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Wed, 21 Jan 2015 20:47:49 -0500 Subject: [PATCH 05/24] boots again --- v/unix.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/v/unix.c b/v/unix.c index d9461da8e..5c7343e0f 100644 --- a/v/unix.c +++ b/v/unix.c @@ -1000,23 +1000,14 @@ _unix_desk_sync_into(u3_noun who, u3_noun syd, u3_udir* dir_u) { - u3_noun xun, bur, doz, fav, pax; + u3_noun xun, fav, pax; xun = _unix_dir_ankh(dir_u); - bur = _unix_desk_peek(hox, u3k(syd), u3k(u3A->wen)); - if ( (c3n == u3r_sing(u3h(xun), u3h(u3t(bur))))) - { - doz = u3dc("cost", xun, u3t(bur)); + pax = u3nq(u3_blip, c3__sync, u3k(u3A->sen), u3_nul); + fav = u3nq(c3__into, who, syd, xun); - pax = u3nq(u3_blip, c3__sync, u3k(u3A->sen), u3_nul); - fav = u3nq(c3__into, who, syd, u3nc(c3y, doz)); - - u3v_plan(pax, fav); - } - else { - u3z(who); u3z(syd); u3z(xun); u3z(bur); - } + u3v_plan(pax, fav); } /* _unix_ship_update(): update top level ship. From a1ef36e02dd061896253b2bf2b25c196fd4906ae Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Fri, 23 Jan 2015 19:13:29 -0500 Subject: [PATCH 06/24] start in/out split --- i/v/vere.h | 9 +++++---- v/sist.c | 10 +++++++++- v/unix.c | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/i/v/vere.h b/i/v/vere.h index c43e60bc1..d707b9cc5 100644 --- a/i/v/vere.h +++ b/i/v/vere.h @@ -294,7 +294,7 @@ struct _u3_udir; struct _u3_ufil; - /* u3_unod: file or directory. + /* u3_unod: in-file or in-directory. */ typedef struct _u3_unod { uv_fs_event_t was_u; // stat watcher @@ -304,7 +304,7 @@ struct _u3_udir* par_u; // in directory } u3_unod; - /* u3_ufil: synchronized file. + /* u3_ufil: synchronized in-file. */ typedef struct _u3_ufil { uv_fs_event_t was_u; // stat watcher @@ -317,7 +317,7 @@ struct _u3_ufil* nex_u; // internal list } u3_ufil; - /* u3_udir: synchronized directory. + /* u3_udir: synchronized in-directory. */ typedef struct _u3_udir { uv_fs_event_t was_u; // stat watcher @@ -333,7 +333,8 @@ /* u3_uhot: synchronized host. */ typedef struct _u3_uhot { - u3_udir dir_u; // root directory + u3_udir dir_u; // in directory + c3_c* dot_u; // out directory c3_w who_w[4]; // owner as words struct _u3_uhot* nex_u; // internal list } u3_uhot; diff --git a/v/sist.c b/v/sist.c index 54beee180..481861dd1 100644 --- a/v/sist.c +++ b/v/sist.c @@ -276,6 +276,7 @@ _sist_sing(u3_noun ovo) static void _sist_home() { + c3_c mak_c[2048]; c3_c ful_c[2048]; // Create subdirectories. @@ -321,7 +322,14 @@ _sist_home() // Copy zod files, if we're generating a carrier. // if ( u3_Host.ops_u.imp_c ) { - snprintf(ful_c, 2048, "cp -r %s/zod %s/%s", + snprintf(mak_c, 2048, "mkdir %s/%s", + u3_Host.dir_c, u3_Host.ops_u.imp_c+1); + printf("%s\r\n", mak_c); + if ( 0 != system(mak_c) ) { + uL(fprintf(uH, "could not %s\n", mak_c)); + u3_lo_bail(); + } + snprintf(ful_c, 2048, "cp -r %s/zod %s/%s/in", U3_LIB, u3_Host.dir_c, u3_Host.ops_u.imp_c+1); printf("%s\r\n", ful_c); if ( 0 != system(ful_c) ) { diff --git a/v/unix.c b/v/unix.c index 5c7343e0f..495ced8f8 100644 --- a/v/unix.c +++ b/v/unix.c @@ -1046,7 +1046,13 @@ _unix_hot_gain(u3_noun who, u3_noun mek) u3_noun hox = u3dc("scot", 'p', u3k(who)); c3_c* hox_c = u3r_string(hox); c3_c* pax_c = _unix_down(u3_Host.dir_c, hox_c + 1); + c3_c* pin_c = _unix_down(pax_c, "in"); + c3_c* pot_c = _unix_down(pax_c, "out"); DIR* rid_u = opendir(pax_c); + DIR* rin_u = opendir(pin_c); + DIR* rot_u = opendir(pot_c); + + free(pax_c); if ( !rid_u ) { if ( c3y == mek ) { @@ -1057,17 +1063,38 @@ _unix_hot_gain(u3_noun who, u3_noun mek) return; } } else closedir(rid_u); + if ( !rin_u ) { + if ( c3y == mek ) { + _unix_mkdir(pin_c); + } else { + u3z(who); + u3z(hox); + return; + } + } else closedir(rin_u); + if ( !rot_u ) { + if ( c3y == mek ) { + _unix_mkdir(pot_c); + } else { + u3z(who); + u3z(hox); + return; + } + } else closedir(rot_u); // uL(fprintf(uH, "GAIN %s\n", pax_c)); free(hox_c); u3z(hox); - u3_unix_acquire(pax_c); + u3_unix_acquire(pin_c); { u3_uhot* hot_u = c3_malloc(sizeof(u3_uhot)); - _unix_dir_watch(&hot_u->dir_u, 0, pax_c); + _unix_dir_watch(&hot_u->dir_u, 0, pin_c); + + hot_u->dot_u = pot_c; + _unix_ship_out(who, hot_u->who_w); u3z(who); @@ -1334,7 +1361,7 @@ u3_unix_ef_init(u3_noun who) u3v_plan(u3nq(u3_blip, c3__sync, u3k(u3A->sen), u3_nul), u3nq(c3__into, who, u3_blip, - u3nt(c3y, u3nc(0, 0), u3_nul))); + u3nt(u3_nul, u3_nul, u3_nul))); } /* u3_unix_ef_ergo(): update filesystem, outbound. @@ -1411,6 +1438,7 @@ u3_unix_ef_look(void) // uL(fprintf(uH, "sync: lose %s\n", hot_u->dir_u.pax_c)); _unix_hot_lose(hot_u); + free(hot_u->dot_u); free(hot_u); continue; } From ab09e78a11a47fc41e5c956460fbb86fe268d1c1 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Tue, 27 Jan 2015 19:57:24 -0500 Subject: [PATCH 07/24] waypoint --- i/v/vere.h | 14 ++++++------ v/unix.c | 63 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 28 deletions(-) diff --git a/i/v/vere.h b/i/v/vere.h index d707b9cc5..b3f85096f 100644 --- a/i/v/vere.h +++ b/i/v/vere.h @@ -300,8 +300,9 @@ uv_fs_event_t was_u; // stat watcher c3_o dir; // always c3_o dry; // ie, unmodified - c3_c* pax_c; // absolute path - struct _u3_udir* par_u; // in directory + c3_c* pax_c; // in absolute path + c3_c* pot_c; // out absolute path + struct _u3_udir* par_u; // directory } u3_unod; /* u3_ufil: synchronized in-file. @@ -310,8 +311,9 @@ uv_fs_event_t was_u; // stat watcher c3_o non; // always u3_no c3_o dry; // ie, unmodified - c3_c* pax_c; // absolute path - struct _u3_udir* par_u; // in directory + c3_c* pax_c; // in absolute path + c3_c* pot_c; // out absolute path + struct _u3_udir* par_u; // directory c3_c* dot_c; // extension point or 0 c3_w mod_w[4]; // mtime struct _u3_ufil* nex_u; // internal list @@ -323,7 +325,8 @@ uv_fs_event_t was_u; // stat watcher c3_o yes; // always u3_yes c3_o dry; // ie, unmodified - c3_c* pax_c; // absolute path + c3_c* pax_c; // in absolute path + c3_c* pot_c; // out absolute path struct _u3_udir* par_u; // parent directory struct _u3_udir* dis_u; // subdirectories struct _u3_ufil* fil_u; // files @@ -334,7 +337,6 @@ */ typedef struct _u3_uhot { u3_udir dir_u; // in directory - c3_c* dot_u; // out directory c3_w who_w[4]; // owner as words struct _u3_uhot* nex_u; // internal list } u3_uhot; diff --git a/v/unix.c b/v/unix.c index 495ced8f8..99fc2edb7 100644 --- a/v/unix.c +++ b/v/unix.c @@ -249,6 +249,7 @@ static void _unix_file_watch(u3_ufil* fil_u, u3_udir* dir_u, c3_c* pax_c, + c3_c* pot_c, c3_w* mod_w) { // (1) build data structure @@ -256,6 +257,7 @@ _unix_file_watch(u3_ufil* fil_u, fil_u->non = c3n; fil_u->dry = c3n; fil_u->pax_c = pax_c; + fil_u->pot_c = pot_c; { c3_c* dot_c = strrchr(pax_c, '.'); c3_c* fas_c = strrchr(pax_c, '/'); @@ -297,45 +299,46 @@ _unix_file_watch(u3_ufil* fil_u, /* _unix_file_form(): form a filename path downward. */ static c3_c* -_unix_file_form(u3_udir* dir_u, +_unix_file_form(c3_c* pax_c, u3_noun pre, u3_noun ket, u3_noun ext) { c3_c* pre_c = u3r_string(pre); c3_c* ext_c = u3r_string(ext); - c3_w pax_w = strlen(dir_u->pax_c); + c3_w pax_w = strlen(pax_c); c3_w pre_w = strlen(pre_c); c3_w ext_w = strlen(ext_c); c3_w ket_w = (c3y == ket) ? 1 : 0; - c3_c* pax_c = c3_malloc(pax_w + 1 + pre_w + 1 + ket_w + ext_w + 1); + c3_c* pox_c = c3_malloc(pax_w + 1 + pre_w + 1 + ket_w + ext_w + 1); - strncpy(pax_c, dir_u->pax_c, pax_w); - pax_c[pax_w] = '/'; - strncpy(pax_c + pax_w + 1, pre_c, pre_w); - pax_c[pax_w + 1 + pre_w] = '.'; + strncpy(pox_c, pax_c, pax_w); + pox_c[pax_w] = '/'; + strncpy(pox_c + pax_w + 1, pre_c, pre_w); + pox_c[pax_w + 1 + pre_w] = '.'; if ( c3y == ket ) { - pax_c[pax_w + 1 + pre_w + 1] = '^'; + pox_c[pax_w + 1 + pre_w + 1] = '^'; } - strncpy(pax_c + pax_w + 1 + pre_w + 1 + ket_w, ext_c, ext_w); - pax_c[pax_w + 1 + pre_w + 1 + ket_w + ext_w] = '\0'; + strncpy(pox_c + pax_w + 1 + pre_w + 1 + ket_w, ext_c, ext_w); + pox_c[pax_w + 1 + pre_w + 1 + ket_w + ext_w] = '\0'; free(pre_c); free(ext_c); u3z(pre); u3z(ext); - return pax_c; + return pox_c; } /* _unix_dir_watch(): instantiate directory tracker. */ static void -_unix_dir_watch(u3_udir* dir_u, u3_udir* par_u, c3_c* pax_c) +_unix_dir_watch(u3_udir* dir_u, u3_udir* par_u, c3_c* pax_c, c3_c* pot_c) { // (1) build data structure // dir_u->yes = c3y; dir_u->dry = c3n; dir_u->pax_c = pax_c; + dir_u->pot_c = pot_c; dir_u->par_u = par_u; dir_u->dis_u = 0; dir_u->fil_u = 0; @@ -372,17 +375,24 @@ _unix_dir_forge(u3_udir* dir_u, u3_udir* par_u, u3_noun tet) c3_w pax_w = strlen(par_u->pax_c); c3_w tet_w = strlen(tet_c); c3_c* pax_c = c3_malloc(pax_w + 1 + tet_w + 1); + c3_c* pot_c = c3_malloc(pax_w + 1 + 1 + tet_w + 1); strncpy(pax_c, par_u->pax_c, pax_w + 1); pax_c[pax_w] = '/'; strncpy(pax_c + pax_w + 1, tet_c, tet_w + 1); pax_c[pax_w + tet_w + 1] = '\0'; + strncpy(pot_c, par_u->pot_c, pax_w + 1 + 1); + pot_c[pax_w + 1] = '/'; + strncpy(pot_c + pax_w + 1 + 1, tet_c, tet_w + 1); + pot_c[pax_w + 1 + tet_w + 1] = '\0'; + free(tet_c); u3z(tet); _unix_mkdir(pax_c); - _unix_dir_watch(dir_u, par_u, pax_c); + _unix_mkdir(pot_c); + _unix_dir_watch(dir_u, par_u, pax_c, pot_c); } /* _unix_file_done(): finish freeing file. @@ -544,11 +554,13 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) } else { c3_c* pax_c = _unix_down(dir_u->pax_c, out_u->d_name); + c3_c* pot_c = _unix_down(dir_u->pot_c, out_u->d_name); struct stat buf_u; // uL(fprintf(uH, " in %s\n", pax_c)); if ( 0 != stat(pax_c, &buf_u) ) { free(pax_c); + free(pot_c); continue; } else { @@ -577,7 +589,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) fil_u = c3_malloc(sizeof(u3_ufil)); // uL(fprintf(uH, "found file %s\n", pax_c)); - _unix_file_watch(fil_u, dir_u, pax_c, mod_w); + _unix_file_watch(fil_u, dir_u, pax_c, pot_c, mod_w); fil_u->nex_u = dir_u->fil_u; dir_u->fil_u = fil_u; @@ -596,7 +608,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) dis_u = c3_malloc(sizeof(u3_udir)); // uL(fprintf(uH, "found directory %s\n", pax_c)); - _unix_dir_watch(dis_u, dir_u, pax_c); + _unix_dir_watch(dis_u, dir_u, pax_c, pot_c); _unix_dir_update(dis_u, red_u); dis_u->nex_u = dir_u->dis_u; @@ -605,6 +617,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) closedir(red_u); } else { free(pax_c); + free(pot_c); } } } @@ -1091,9 +1104,7 @@ _unix_hot_gain(u3_noun who, u3_noun mek) { u3_uhot* hot_u = c3_malloc(sizeof(u3_uhot)); - _unix_dir_watch(&hot_u->dir_u, 0, pin_c); - - hot_u->dot_u = pot_c; + _unix_dir_watch(&hot_u->dir_u, 0, pin_c, pot_c); _unix_ship_out(who, hot_u->who_w); u3z(who); @@ -1165,8 +1176,10 @@ _unix_desk_sync_tofu(u3_udir* dir_u, u3_noun ext, u3_noun mis) { - c3_c* pox_c = _unix_file_form(dir_u, u3k(pre), c3n, u3k(ext)); - c3_c* pux_c = _unix_file_form(dir_u, u3k(pre), c3y, u3k(ext)); + c3_c* pox_c = _unix_file_form(dir_u->pax_c, u3k(pre), c3n, u3k(ext)); + c3_c* pot_c = _unix_file_form(dir_u->pot_c, u3k(pre), c3n, u3k(ext)); + c3_c* pux_c = _unix_file_form(dir_u->pax_c, u3k(pre), c3y, u3k(ext)); + c3_c* put_c = _unix_file_form(dir_u->pot_c, u3k(pre), c3y, u3k(ext)); u3_ufil** fil_u; // uL(fprintf(uH, "tofu pox_c %s op %s\n", pox_c, u3r_string(u3h(mis)))); @@ -1203,11 +1216,14 @@ _unix_desk_sync_tofu(u3_udir* dir_u, _unix_file_free(ded_u); free(pox_c); + free(pot_c); free(pux_c); + free(put_c); } else { u3_noun god, oat; c3_c* pax_c; + c3_c* pat_c; if ( *fil_u ) { u3_noun old = _unix_file_load(*fil_u); @@ -1225,9 +1241,11 @@ _unix_desk_sync_tofu(u3_udir* dir_u, if ( c3y == u3du(god) ) { oat = u3ke_jam(god); pax_c = pux_c; free(pox_c); + pat_c = put_c; free(pot_c); } else { oat = god; pax_c = pox_c; free(pux_c); + pat_c = pot_c; free(put_c); } #ifdef SYNCLOG @@ -1238,10 +1256,12 @@ _unix_desk_sync_tofu(u3_udir* dir_u, #endif _unix_save(pax_c, oat); + _unix_save(pat_c, oat); if ( *fil_u ) { (*fil_u)->dot_c = (pax_c + ((*fil_u)->dot_c - (*fil_u)->pax_c)); (*fil_u)->pax_c = pax_c; + (*fil_u)->pot_c = pat_c; u3r_words(0, 4, (*fil_u)->mod_w, u3A->now); } @@ -1251,7 +1271,7 @@ _unix_desk_sync_tofu(u3_udir* dir_u, u3r_words(0, 4, mod_w, u3A->now); *fil_u = c3_malloc(sizeof(u3_ufil)); - _unix_file_watch(*fil_u, dir_u, pax_c, mod_w); + _unix_file_watch(*fil_u, dir_u, pax_c, pat_c, mod_w); } } u3z(pre); u3z(ext); u3z(mis); @@ -1438,7 +1458,6 @@ u3_unix_ef_look(void) // uL(fprintf(uH, "sync: lose %s\n", hot_u->dir_u.pax_c)); _unix_hot_lose(hot_u); - free(hot_u->dot_u); free(hot_u); continue; } From f86e6c4d351c9934f4ec8dc007e133b9a9d5d3ee Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Wed, 28 Jan 2015 20:28:10 -0500 Subject: [PATCH 08/24] waypoint --- Makefile | 2 +- i/v/vere.h | 3 +- v/reck.c | 5 +-- v/sist.c | 8 +++++ v/unix.c | 91 ++++++++++++++++++++++++------------------------------ 5 files changed, 54 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index e1e95c43c..138aae7f3 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ INCLUDE=i MDEFINES=-DU3_OS_$(OS) -DU3_OS_ENDIAN_$(ENDIAN) -D U3_LIB=\"$(LIB)\" # NOTFORCHECKIN - restore -O3 -CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ +CFLAGS= $(COSFLAGS) -g -msse3 -ffast-math \ -funsigned-char \ -I/usr/local/include \ -I/opt/local/include \ diff --git a/i/v/vere.h b/i/v/vere.h index b3f85096f..bb1a2c518 100644 --- a/i/v/vere.h +++ b/i/v/vere.h @@ -929,7 +929,8 @@ void u3_unix_ef_ergo(u3_noun who, u3_noun syd, - u3_noun rel); + u3_noun rel, + u3_noun can); /* u3_unix_io_init(): initialize storage. */ diff --git a/v/reck.c b/v/reck.c index 32366d8a7..e751653b8 100644 --- a/v/reck.c +++ b/v/reck.c @@ -156,9 +156,10 @@ _reck_kick_sync(u3_noun pox, u3_noun fav) case c3__ergo: { u3_noun who = u3k(u3h(u3t(fav))); u3_noun syd = u3k(u3h(u3t(u3t(fav)))); - u3_noun rel = u3k(u3t(u3t(u3t(fav)))); + u3_noun rel = u3k(u3h(u3t(u3t(u3t(fav))))); + u3_noun can = u3k(u3t(u3t(u3t(u3t(fav))))); - u3_unix_ef_ergo(who, syd, rel); + u3_unix_ef_ergo(who, syd, rel, can); u3z(pox); u3z(fav); return c3y; } break; } diff --git a/v/sist.c b/v/sist.c index 481861dd1..ee5265647 100644 --- a/v/sist.c +++ b/v/sist.c @@ -278,6 +278,7 @@ _sist_home() { c3_c mak_c[2048]; c3_c ful_c[2048]; + c3_c fut_c[2048]; // Create subdirectories. // @@ -336,6 +337,13 @@ _sist_home() uL(fprintf(uH, "could not %s\n", ful_c)); u3_lo_bail(); } + snprintf(fut_c, 2048, "cp -r %s/zod %s/%s/out", + U3_LIB, u3_Host.dir_c, u3_Host.ops_u.imp_c+1); + printf("%s\r\n", fut_c); + if ( 0 != system(fut_c) ) { + uL(fprintf(uH, "could not %s\n", fut_c)); + u3_lo_bail(); + } } #endif } diff --git a/v/unix.c b/v/unix.c index 99fc2edb7..6b1628212 100644 --- a/v/unix.c +++ b/v/unix.c @@ -682,7 +682,7 @@ static void _unix_save(c3_c* pax_c, u3_atom oat) { c3_i fid_i = open(pax_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); - c3_w fln_w, rit_w; + c3_w fln_w, rit_w, siz_w; c3_y* oat_y; if ( fid_i < 0 ) { @@ -690,12 +690,15 @@ _unix_save(c3_c* pax_c, u3_atom oat) u3m_bail(c3__fail); } - fln_w = u3r_met(3, oat); - oat_y = c3_malloc(fln_w); - u3r_bytes(0, fln_w, oat_y, oat); + siz_w = u3h(u3t(oat)); + fln_w = u3r_met(3, u3t(u3t(oat))); + oat_y = c3_malloc(siz_w); + memset(oat_y, 0, siz_w); + + u3r_bytes(0, fln_w, oat_y, u3t(u3t(oat))); u3z(oat); - rit_w = write(fid_i, oat_y, fln_w); + rit_w = write(fid_i, oat_y, siz_w); if ( rit_w != fln_w ) { uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); c3_assert(0); @@ -908,6 +911,7 @@ _find_mug(u3_noun som, c3_l mug_l) } #endif +#if 0 /* _unix_desk_peek(): peek for ankh. */ static u3_noun @@ -930,6 +934,7 @@ _unix_desk_peek(u3_noun hox, u3z(cay); return ank; } } +#endif #if 0 /* _unix_ankh_sing_map(): compare ankh maps for u3_ankh_sing(). @@ -1160,6 +1165,7 @@ _unix_home(u3_noun who) return hot_u; } +#if 0 /* _unix_desk_sync_udon(): apply udon to existing value. */ static u3_noun @@ -1167,6 +1173,7 @@ _unix_desk_sync_udon(u3_noun don, u3_noun old) { return u3dc("lump", don, old); } +#endif /* _unix_desk_sync_tofu(): sync out file install. */ @@ -1174,7 +1181,7 @@ static void _unix_desk_sync_tofu(u3_udir* dir_u, u3_noun pre, u3_noun ext, - u3_noun mis) + u3_noun mim) { c3_c* pox_c = _unix_file_form(dir_u->pax_c, u3k(pre), c3n, u3k(ext)); c3_c* pot_c = _unix_file_form(dir_u->pot_c, u3k(pre), c3n, u3k(ext)); @@ -1201,6 +1208,7 @@ _unix_desk_sync_tofu(u3_udir* dir_u, else fil_u = &((*fil_u)->nex_u); } +#if 0 if ( *fil_u && (c3__del == u3h(mis)) ) { u3_ufil* ded_u = *fil_u; @@ -1221,32 +1229,26 @@ _unix_desk_sync_tofu(u3_udir* dir_u, free(put_c); } else { - u3_noun god, oat; +#endif c3_c* pax_c; c3_c* pat_c; if ( *fil_u ) { - u3_noun old = _unix_file_load(*fil_u); - c3_assert(c3__mut == u3h(mis)); - - god = _unix_desk_sync_udon(u3k(u3t(mis)), old); _unix_unlink((*fil_u)->pax_c); free((*fil_u)->pax_c); } - else { - c3_assert(c3__ins == u3h(mis)); - god = u3k(u3t(mis)); - } +#if 0 if ( c3y == u3du(god) ) { - oat = u3ke_jam(god); pax_c = pux_c; free(pox_c); pat_c = put_c; free(pot_c); } else { - oat = god; +#endif pax_c = pox_c; free(pux_c); pat_c = pot_c; free(put_c); +#if 0 } +#endif #ifdef SYNCLOG u3_Host.unx_u.sylo[slot].unx = c3n; @@ -1255,8 +1257,8 @@ _unix_desk_sync_tofu(u3_udir* dir_u, u3_Host.unx_u.sylo[slot].pax_c = strdup(pax_c); #endif - _unix_save(pax_c, oat); - _unix_save(pat_c, oat); + _unix_save(pax_c, mim); + _unix_save(pat_c, mim); if ( *fil_u ) { (*fil_u)->dot_c = (pax_c + ((*fil_u)->dot_c - (*fil_u)->pax_c)); @@ -1273,14 +1275,16 @@ _unix_desk_sync_tofu(u3_udir* dir_u, _unix_file_watch(*fil_u, dir_u, pax_c, pat_c, mod_w); } +#if 0 } - u3z(pre); u3z(ext); u3z(mis); +#endif + u3z(pre); u3z(ext); u3z(mim); } /* _unix_desk_sync_tako(): sync out change. */ static void -_unix_desk_sync_tako(u3_udir* dir_u, u3_noun pax, u3_noun mis) +_unix_desk_sync_tako(u3_udir* dir_u, u3_noun pax, u3_noun mim) { if ( (c3n == u3du(pax)) ) { c3_assert(!"tack"); @@ -1292,7 +1296,7 @@ _unix_desk_sync_tako(u3_udir* dir_u, u3_noun pax, u3_noun mis) u3_noun pem = u3i_string(par_u); c3_assert( u3_nul == t_pax ); // XX ugly, wrong - _unix_desk_sync_tofu(dir_u->par_u, pem, u3k(i_pax), mis); + _unix_desk_sync_tofu(dir_u->par_u, pem, u3k(i_pax), mim); } else { u3_noun i_pax = u3h(pax); @@ -1301,7 +1305,7 @@ _unix_desk_sync_tako(u3_udir* dir_u, u3_noun pax, u3_noun mis) u3_noun tt_pax = u3t(t_pax); if ( u3_nul == tt_pax ) { - _unix_desk_sync_tofu(dir_u, u3k(i_pax), u3k(it_pax), mis); + _unix_desk_sync_tofu(dir_u, u3k(i_pax), u3k(it_pax), mim); } else { u3_udir** dis_u = _unix_pdir(dir_u, u3k(i_pax)); @@ -1311,7 +1315,7 @@ _unix_desk_sync_tako(u3_udir* dir_u, u3_noun pax, u3_noun mis) _unix_dir_forge(*dis_u, dir_u, u3k(i_pax)); } - _unix_desk_sync_tako(*dis_u, u3k(t_pax), mis); + _unix_desk_sync_tako(*dis_u, u3k(t_pax), mim); } } u3z(pax); @@ -1320,15 +1324,13 @@ _unix_desk_sync_tako(u3_udir* dir_u, u3_noun pax, u3_noun mis) /* _unix_desk_sync_soba(): sync computed changes. */ static void -_unix_desk_sync_soba(u3_udir* dir_u, u3_noun doz) +_unix_desk_sync_list(u3_udir* dir_u, u3_noun can) { - u3_noun zod = u3t(doz); - - while ( u3_nul != zod ) { - _unix_desk_sync_tako(dir_u, u3k(u3h(u3h(zod))), u3k(u3t(u3h(zod)))); - zod = u3t(zod); + while ( u3_nul != can ) { + _unix_desk_sync_tako(dir_u, u3k(u3h(u3h(can))), u3k(u3t(u3h(can)))); + can = u3t(can); } - u3z(doz); + u3z(can); } /* _unix_desk_sync_ergo(): sync desk changes to unix. @@ -1337,10 +1339,10 @@ static void _unix_desk_sync_ergo(u3_noun hox, u3_noun syd, u3_noun lok, + u3_noun can, u3_uhot* hot_u) { u3_udir** dir_u = _unix_pdir(&(hot_u->dir_u), syd); - u3_noun xun; #if 0 uL(fprintf(uH, "ergo %s %s %s\n", u3r_string(hox), @@ -1351,24 +1353,10 @@ _unix_desk_sync_ergo(u3_noun hox, if ( !*dir_u ) { *dir_u = c3_malloc(sizeof(u3_udir)); - xun = u3nt(0, u3_nul, u3_nul); _unix_dir_forge(*dir_u, &(hot_u->dir_u), u3k(syd)); - } else { - xun = _unix_dir_ankh(*dir_u); } - { - u3_noun bur = _unix_desk_peek(hox, syd, lok); - - if ( c3n == u3r_sing(xun, bur) ) { - u3_noun doz = u3dc("cost", bur, xun); - - _unix_desk_sync_soba(*dir_u, doz); - } - else { - u3z(xun); u3z(bur); - } - } + _unix_desk_sync_list(*dir_u, can); } /* u3_unix_ef_init(): update filesystem for new acquisition. @@ -1389,16 +1377,17 @@ u3_unix_ef_init(u3_noun who) void u3_unix_ef_ergo(u3_noun who, u3_noun syd, - u3_noun rel) + u3_noun rel, + u3_noun can) { - u3_noun hox = u3dc("scot", 'p', u3k(who)); - u3_noun lok = u3dc("scot", c3__ud, rel); + u3_noun hox = u3dc("scot", 'p', u3k(who)); // XXX unnecessary? + u3_noun lok = u3dc("scot", c3__ud, rel); // XXX unnecessary? u3_uhot* hot_u; hot_u = _unix_home(who); if ( 0 != hot_u ) { - _unix_desk_sync_ergo(hox, syd, lok, hot_u); + _unix_desk_sync_ergo(hox, syd, lok, can, hot_u); } } From 1b5c21f4f43c1b7922aee0e0460f093f42f03d9e Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Thu, 29 Jan 2015 14:47:51 -0500 Subject: [PATCH 09/24] working in/out --- v/unix.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/v/unix.c b/v/unix.c index 6b1628212..b698f99af 100644 --- a/v/unix.c +++ b/v/unix.c @@ -105,8 +105,8 @@ _unix_opendir(c3_c* pax_c) static void _unix_unlink(c3_c* pax_c) { - if ( 0 != unlink(pax_c) && ENOENT != errno) { - uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); + if ( 0 != unlink(pax_c) /* && ENOENT != errno */) { + uL(fprintf(uH, "error unlinking %s: %s\n", pax_c, strerror(errno))); c3_assert(0); } } @@ -686,7 +686,7 @@ _unix_save(c3_c* pax_c, u3_atom oat) c3_y* oat_y; if ( fid_i < 0 ) { - uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); + uL(fprintf(uH, "error opening %s: %s\n", pax_c, strerror(errno))); u3m_bail(c3__fail); } @@ -699,8 +699,8 @@ _unix_save(c3_c* pax_c, u3_atom oat) u3z(oat); rit_w = write(fid_i, oat_y, siz_w); - if ( rit_w != fln_w ) { - uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); + if ( rit_w != siz_w ) { + uL(fprintf(uH, "error writing %s: %s\n", pax_c, strerror(errno))); c3_assert(0); } @@ -1200,8 +1200,8 @@ _unix_desk_sync_tofu(u3_udir* dir_u, fil_u = &(dir_u->fil_u); while ( 1 ) { // XX crude! if ( !*fil_u || - !strcmp((*fil_u)->pax_c, pox_c) || - !strcmp((*fil_u)->pax_c, pux_c) ) + !strcmp((*fil_u)->pax_c, pox_c) /* || + !strcmp((*fil_u)->pax_c, pux_c) */ ) { break; } @@ -1236,6 +1236,8 @@ _unix_desk_sync_tofu(u3_udir* dir_u, if ( *fil_u ) { _unix_unlink((*fil_u)->pax_c); free((*fil_u)->pax_c); + _unix_unlink((*fil_u)->pot_c); + free((*fil_u)->pot_c); } #if 0 @@ -1257,7 +1259,7 @@ _unix_desk_sync_tofu(u3_udir* dir_u, u3_Host.unx_u.sylo[slot].pax_c = strdup(pax_c); #endif - _unix_save(pax_c, mim); + _unix_save(pax_c, u3k(mim)); _unix_save(pat_c, mim); if ( *fil_u ) { From 28841a3e74e8782ae8cae83e6459b3e4b3b8b78a Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Thu, 29 Jan 2015 20:06:02 -0500 Subject: [PATCH 10/24] waypoint --- v/unix.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/v/unix.c b/v/unix.c index b698f99af..0dfdd94ac 100644 --- a/v/unix.c +++ b/v/unix.c @@ -626,7 +626,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) } } -/* unix_load(): load a file. +/* unix_load(): load a file as a cage */ static u3_noun _unix_load(c3_c* pax_c) @@ -657,16 +657,16 @@ _unix_load(c3_c* pax_c) else { // -:!>(*[[@tas @tas ~] @ud @]) u3_noun typ = u3nt(c3__cell, - u3nt(c3__cell, - u3nc(c3__atom, c3__tas), - u3nt(c3__cell, - u3nc(c3__atom, c3__tas), - u3nt(c3__cube, - u3_nul, - u3nc(c3__atom, 'n')))), - u3nt(c3__cell, - u3nc(c3__atom, c3__ud), - u3nc(c3__atom, u3_nul))); + u3nt(c3__cell, + u3nc(c3__atom, c3__tas), + u3nt(c3__cell, + u3nc(c3__atom, c3__tas), + u3nt(c3__cube, + u3_nul, + u3nc(c3__atom, 'n')))), + u3nt(c3__cell, + u3nc(c3__atom, c3__ud), + u3nc(c3__atom, u3_nul))); u3_noun nam = u3nt(c3__text, u3i_string("plain"), u3_nul); u3_noun pad = u3nt(nam, fln_w, u3i_bytes(fln_w, (c3_y *)pad_y)); u3_noun cay = u3nt(c3__mime, typ, pad); @@ -882,6 +882,7 @@ _unix_dir_ankh(u3_udir* dir_u) for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { u3_noun wib = _unix_file_name(fil_u); u3_noun baw = _unix_file_load(fil_u); + if (0 == baw) continue; u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(u3t(u3t(baw)))), baw); pam = _unix_dir_ankh_file(pam, wib, baw, woz); } @@ -1208,8 +1209,8 @@ _unix_desk_sync_tofu(u3_udir* dir_u, else fil_u = &((*fil_u)->nex_u); } -#if 0 - if ( *fil_u && (c3__del == u3h(mis)) ) { + if ( *fil_u && u3_nul == mim ) { + uL(fprintf(uH, "file goning: %s\n", pox_c)); u3_ufil* ded_u = *fil_u; #ifdef SYNCLOG @@ -1221,7 +1222,17 @@ _unix_desk_sync_tofu(u3_udir* dir_u, *fil_u = ded_u->nex_u; _unix_unlink(ded_u->pax_c); + _unix_unlink(ded_u->pot_c); _unix_file_free(ded_u); + free(ded_u->pot_c); + + free(pox_c); + free(pot_c); + free(pux_c); + free(put_c); + } + else if (u3_nul == mim) { + uL(fprintf(uH, "file already gone: %s\n", pox_c)); free(pox_c); free(pot_c); @@ -1229,7 +1240,6 @@ _unix_desk_sync_tofu(u3_udir* dir_u, free(put_c); } else { -#endif c3_c* pax_c; c3_c* pat_c; @@ -1259,8 +1269,8 @@ _unix_desk_sync_tofu(u3_udir* dir_u, u3_Host.unx_u.sylo[slot].pax_c = strdup(pax_c); #endif - _unix_save(pax_c, u3k(mim)); - _unix_save(pat_c, mim); + _unix_save(pax_c, u3k(u3t(mim))); + _unix_save(pat_c, u3t(mim)); if ( *fil_u ) { (*fil_u)->dot_c = (pax_c + ((*fil_u)->dot_c - (*fil_u)->pax_c)); @@ -1277,9 +1287,8 @@ _unix_desk_sync_tofu(u3_udir* dir_u, _unix_file_watch(*fil_u, dir_u, pax_c, pat_c, mod_w); } -#if 0 } -#endif + u3z(pre); u3z(ext); u3z(mim); } From f7455b7db81a476202e631b2ac5b24cb7db1b72d Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Fri, 30 Jan 2015 19:40:07 -0500 Subject: [PATCH 11/24] deletion works --- v/unix.c | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/v/unix.c b/v/unix.c index 0dfdd94ac..fe0527610 100644 --- a/v/unix.c +++ b/v/unix.c @@ -105,7 +105,7 @@ _unix_opendir(c3_c* pax_c) static void _unix_unlink(c3_c* pax_c) { - if ( 0 != unlink(pax_c) /* && ENOENT != errno */) { + if ( 0 != unlink(pax_c) && ENOENT != errno ) { uL(fprintf(uH, "error unlinking %s: %s\n", pax_c, strerror(errno))); c3_assert(0); } @@ -778,21 +778,21 @@ _unix_file_name(u3_ufil* fil_u) } } -/* _unix_dir_ankh_file(): process a file for ankh. +/* _unix_dir_khan_file(): process a file for khan. */ static u3_noun -_unix_dir_ankh_file(u3_noun pam, u3_noun wib, u3_noun baw, u3_noun woz) +_unix_dir_khan_file(u3_noun pam, u3_noun wib, u3_noun baw, u3_noun woz) { u3_weak ole; if ( c3n == u3du(wib) ) { ole = u3kdb_get(u3k(pam), u3k(wib)); if ( u3_none == ole ) { - ole = u3do("cosh", u3nt(0, woz, u3_nul)); + ole = u3nc(woz, u3_nul); } else { u3_noun elo; - elo = u3do("cosh", u3nt(0, woz, u3k(u3t(u3t(ole))))); + elo = u3nc(woz, u3k(u3t(ole))); u3z(ole); ole = elo; @@ -806,29 +806,28 @@ _unix_dir_ankh_file(u3_noun pam, u3_noun wib, u3_noun baw, u3_noun woz) ole = u3kdb_get(u3k(pam), u3k(fid)); if ( u3_none == ole ) { - ole = u3nt - (0, u3_nul, u3kdb_put(u3_nul, - u3k(har), - u3do("cosh", u3nt(0, woz, u3_nul)))); - ole = u3do("cosh", ole); + ole = u3nc(u3_nul, + u3kdb_put(u3_nul, + u3k(har), + u3nc(woz, u3_nul))); } else { - u3_noun roo = u3t(u3t(ole)); + u3_noun roo = u3t(ole); u3_weak tup = u3kdb_get(u3k(roo), u3k(har)); u3_noun oor, elo; if ( u3_none == tup ) { - tup = u3do("cosh", u3nt(0, woz, u3_nul)); + tup = u3nc(woz, u3_nul); } else { u3_noun upt; - upt = u3do("cosh", u3nt(0, woz, u3k(u3t(u3t(tup))))); + upt = u3nc(woz, u3k(u3t(tup))); u3z(tup); tup = upt; } oor = u3kdb_put(u3k(roo), u3k(har), tup); - elo = u3do("cosh", u3nt(0, u3k(u3h(u3t(ole))), oor)); + elo = u3nc(u3k(u3h(ole)), oor); u3z(ole); ole = elo; } @@ -838,10 +837,10 @@ _unix_dir_ankh_file(u3_noun pam, u3_noun wib, u3_noun baw, u3_noun woz) return pam; } -/* _unix_dir_ankh(): resolve directory to new style ankh. +/* _unix_dir_khan(): resolve directory to khan. */ static u3_noun -_unix_dir_ankh(u3_udir* dir_u) +_unix_dir_khan(u3_udir* dir_u) { u3_udir* dis_u; u3_ufil* fil_u; @@ -849,15 +848,15 @@ _unix_dir_ankh(u3_udir* dir_u) for ( dis_u = dir_u->dis_u; dis_u; dis_u = dis_u->nex_u ) { u3_noun pre = _unix_dir_name(dis_u); - u3_noun ank = _unix_dir_ankh(dis_u); + u3_noun kan = _unix_dir_khan(dis_u); // uL(fprintf(uH, "dir %s\n", u3r_string(pre))); - if ( 0 != u3h(ank) ) { - pam = u3kdb_put(pam, pre, ank); + if ( u3_nul != u3h(kan) || u3_nul != u3t(kan) ) { + pam = u3kdb_put(pam, pre, kan); } else { - u3z(ank); + u3z(kan); } } @@ -874,7 +873,7 @@ _unix_dir_ankh(u3_udir* dir_u) u3_noun baw = _unix_file_load(fil_u); u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(u3t(u3t(baw)))), baw); u3z(dur); - pam = _unix_dir_ankh_file(pam, u3k(u3t(wib)), baw, woz); + pam = _unix_dir_khan_file(pam, u3k(u3t(wib)), baw, woz); u3z(wib); } } @@ -882,11 +881,13 @@ _unix_dir_ankh(u3_udir* dir_u) for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { u3_noun wib = _unix_file_name(fil_u); u3_noun baw = _unix_file_load(fil_u); - if (0 == baw) continue; - u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(u3t(u3t(baw)))), baw); - pam = _unix_dir_ankh_file(pam, wib, baw, woz); + if (0 == baw) { + pam = _unix_dir_khan_file(pam, wib, baw, u3nc(u3_nul, u3_nul)); + } else { + pam = _unix_dir_khan_file(pam, wib, baw, u3nt(u3_nul, u3_nul, baw)); + } } - return u3do("cosh", u3nt(0, u3_nul, pam)); + return u3nc(u3_nul, pam); } /* _find_mug(): find a noun with a given mug. retain. DELETEME @@ -1021,7 +1022,7 @@ _unix_desk_sync_into(u3_noun who, { u3_noun xun, fav, pax; - xun = _unix_dir_ankh(dir_u); + xun = _unix_dir_khan(dir_u); pax = u3nq(u3_blip, c3__sync, u3k(u3A->sen), u3_nul); fav = u3nq(c3__into, who, syd, xun); @@ -1380,7 +1381,7 @@ u3_unix_ef_init(u3_noun who) u3v_plan(u3nq(u3_blip, c3__sync, u3k(u3A->sen), u3_nul), u3nq(c3__into, who, u3_blip, - u3nt(u3_nul, u3_nul, u3_nul))); + u3nc(u3_nul, u3_nul))); } /* u3_unix_ef_ergo(): update filesystem, outbound. From 6888ba9f95ed53374deedc8802556be37aceae94 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Mon, 2 Feb 2015 19:50:45 -0500 Subject: [PATCH 12/24] performance --- v/sist.c | 16 ++++----- v/unix.c | 106 ++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 90 insertions(+), 32 deletions(-) diff --git a/v/sist.c b/v/sist.c index ee5265647..8223ae45d 100644 --- a/v/sist.c +++ b/v/sist.c @@ -278,7 +278,7 @@ _sist_home() { c3_c mak_c[2048]; c3_c ful_c[2048]; - c3_c fut_c[2048]; + // c3_c fut_c[2048]; // Create subdirectories. // @@ -337,13 +337,13 @@ _sist_home() uL(fprintf(uH, "could not %s\n", ful_c)); u3_lo_bail(); } - snprintf(fut_c, 2048, "cp -r %s/zod %s/%s/out", - U3_LIB, u3_Host.dir_c, u3_Host.ops_u.imp_c+1); - printf("%s\r\n", fut_c); - if ( 0 != system(fut_c) ) { - uL(fprintf(uH, "could not %s\n", fut_c)); - u3_lo_bail(); - } + // snprintf(fut_c, 2048, "cp -r %s/zod %s/%s/out", + // U3_LIB, u3_Host.dir_c, u3_Host.ops_u.imp_c+1); + // printf("%s\r\n", fut_c); + // if ( 0 != system(fut_c) ) { + // uL(fprintf(uH, "could not %s\n", fut_c)); + // u3_lo_bail(); + // } } #endif } diff --git a/v/unix.c b/v/unix.c index fe0527610..4418e8738 100644 --- a/v/unix.c +++ b/v/unix.c @@ -16,13 +16,14 @@ #include #include #include +#include #include "all.h" #include "v/vere.h" /* _unix_ship_in(): c3_w[4] to ship. */ -static u3_noun +static u3_noun _unix_ship_in(c3_w* who_w) { return u3i_words(4, who_w); @@ -81,6 +82,42 @@ _unix_mkdir(c3_c* pax_c) } } +/* _unix_mkpath(): mkdir -p, asserting + * + * adapted from + * http://niallohiggins.com/2009/01/08/mkpath-mkdir-p-alike-in-c-for-unix/ + */ +static void +_unix_mkpath(const char *s) +{ + char *q, *r = NULL, *path = NULL, *up = NULL; + + if (strcmp(s, ".") == 0 || strcmp(s, "/") == 0) + return; + + if ((path = strdup(s)) == NULL) + c3_assert(0); + + if ((q = strdup(s)) == NULL) + c3_assert(0); + + if ((r = dirname(q)) == NULL) + goto out; + + if ((up = strdup(r)) == NULL) + exit(1); + + _unix_mkpath(up); + + _unix_mkdir(path); + +out: + if (up != NULL) + free(up); + free(q); + free(path); +} + /* _unix_opendir(): opendir, recreating if nonexistent. */ static DIR* @@ -213,7 +250,7 @@ _unix_fs_event_cb(uv_fs_event_t* was_u, c3_i evt_i, c3_i sas_i) { - + // note that we're doing something tricky and weird here. // // * libuv passes around a pointer to a uv_fs_event_t @@ -277,7 +314,7 @@ _unix_file_watch(u3_ufil* fil_u, // (2) stuff data structure into libuv // c3_w ret_w = uv_fs_event_init(u3L, // loop - &fil_u->was_u // uv_fs_event_t + &fil_u->was_u // uv_fs_event_t ); if (0 != ret_w){ uL(fprintf(uH, "event init: %s\n", strerror(ret_w))); @@ -576,7 +613,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) { u3_noun mod = c3_stat_mtime(&buf_u); - + u3r_words(0, 4, mod_w, mod); u3z(mod); } @@ -586,6 +623,7 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) } } if ( !fil_u ) { + fprintf(stderr, "new filez!\r\n"); fil_u = c3_malloc(sizeof(u3_ufil)); // uL(fprintf(uH, "found file %s\n", pax_c)); @@ -627,21 +665,26 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) } /* unix_load(): load a file as a cage + * + * return value of c3__none means delete, u3_nul means no change */ static u3_noun -_unix_load(c3_c* pax_c) +_unix_load(u3_ufil* fil_u) { struct stat buf_u; - c3_i fid_i = open(pax_c, O_RDONLY, 0644); + c3_i fid_i = open(fil_u->pax_c, O_RDONLY, 0644); c3_w fln_w, red_w; c3_y* pad_y; + c3_i fit_i = open(fil_u->pot_c, O_RDONLY, 0644); + c3_w flt_w, ret_w; + c3_y* pat_y; if ( (fid_i < 0) || (fstat(fid_i, &buf_u) < 0) ) { // ignore if the file disappeared between getting the sync event and now if ( ENOENT != errno ) { - uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno))); + uL(fprintf(uH, "error loading %s: %s\n", fil_u->pax_c, strerror(errno))); } - return 0; + return c3__none; } fln_w = buf_u.st_size; pad_y = c3_malloc(fln_w); @@ -655,6 +698,27 @@ _unix_load(c3_c* pax_c) return 0; } else { + if ( !(fit_i < 0 || fstat(fit_i, &buf_u) < 0) ) { + flt_w = buf_u.st_size; + pat_y = c3_malloc(flt_w); + + ret_w = read(fit_i, pat_y, flt_w); + close(fit_i); + + if ( flt_w != ret_w ) { + free(pad_y); + c3_assert(0); + return 0; + } + + if ( fln_w == flt_w && 0 == memcmp(pad_y, pat_y, fln_w) ) { + free(pat_y); + return u3_nul; + } + + free(pat_y); + } + // -:!>(*[[@tas @tas ~] @ud @]) u3_noun typ = u3nt(c3__cell, u3nt(c3__cell, @@ -681,6 +745,10 @@ _unix_load(c3_c* pax_c) static void _unix_save(c3_c* pax_c, u3_atom oat) { + c3_c* dir = strdup(pax_c); + _unix_mkpath(dirname(dir)); + free(dir); + c3_i fid_i = open(pax_c, O_WRONLY | O_CREAT | O_TRUNC, 0666); c3_w fln_w, rit_w, siz_w; c3_y* oat_y; @@ -713,18 +781,9 @@ _unix_save(c3_c* pax_c, u3_atom oat) static u3_noun _unix_file_load(u3_ufil* fil_u) { - return _unix_load(fil_u->pax_c); - -#if 0 - if ( (0 == raw) || ('^' != fil_u->dot_c[1]) ) { - return raw; - } - - else return u3ke_cue(raw); -#endif + return _unix_load(fil_u); } - /* _unix_dir_name(): directory name. */ static u3_noun @@ -871,7 +930,7 @@ _unix_dir_khan(u3_udir* dir_u) continue; } u3_noun baw = _unix_file_load(fil_u); - u3_noun woz = u3nt(u3_nul, u3do("sham", u3k(u3t(u3t(baw)))), baw); + u3_noun woz = u3nt(u3_nul, u3_nul, baw); u3z(dur); pam = _unix_dir_khan_file(pam, u3k(u3t(wib)), baw, woz); u3z(wib); @@ -881,11 +940,10 @@ _unix_dir_khan(u3_udir* dir_u) for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { u3_noun wib = _unix_file_name(fil_u); u3_noun baw = _unix_file_load(fil_u); - if (0 == baw) { - pam = _unix_dir_khan_file(pam, wib, baw, u3nc(u3_nul, u3_nul)); - } else { - pam = _unix_dir_khan_file(pam, wib, baw, u3nt(u3_nul, u3_nul, baw)); - } + u3_noun wol = (c3__none == baw ? u3nc(u3_nul, u3_nul) : + u3_nul == baw ? u3_nul : + u3nt(u3_nul, u3_nul, baw)); + pam = _unix_dir_khan_file(pam, wib, baw, wol); } return u3nc(u3_nul, pam); } From 66662f2b41671f37a56f22f9710a8cc432e247f1 Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Wed, 18 Feb 2015 19:53:28 -0500 Subject: [PATCH 13/24] ford %join --- v/unix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/v/unix.c b/v/unix.c index 4418e8738..c8e44410d 100644 --- a/v/unix.c +++ b/v/unix.c @@ -1291,7 +1291,7 @@ _unix_desk_sync_tofu(u3_udir* dir_u, free(put_c); } else if (u3_nul == mim) { - uL(fprintf(uH, "file already gone: %s\n", pox_c)); + uL(fprintf(uH, "file already gone: %s\n", pox_c)); // fires too often free(pox_c); free(pot_c); From ff7904904dbcc788432078361d1671840410314e Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Wed, 8 Apr 2015 17:29:19 -0700 Subject: [PATCH 14/24] Fix ^F bug. --- v/term.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/v/term.c b/v/term.c index ecd33d705..199243edb 100644 --- a/v/term.c +++ b/v/term.c @@ -832,9 +832,11 @@ _term_io_suck_char(u3_utty* uty_u, c3_y cay_y) else if ( 13 == cay_y ) { _term_io_belt(uty_u, u3nc(c3__ret, u3_nul)); } +#if 0 else if ( 6 == cay_y ) { _term_io_flow(uty_u); // XX hack } +#endif else if ( cay_y <= 26 ) { _term_io_belt(uty_u, u3nc(c3__ctl, ('a' + (cay_y - 1)))); } From c1617611eda85e347d4d827e4f58d21df2b5ec6a Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Thu, 30 Apr 2015 15:58:34 -0700 Subject: [PATCH 15/24] Remove debug hack. --- v/term.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/v/term.c b/v/term.c index 199243edb..7934df5b4 100644 --- a/v/term.c +++ b/v/term.c @@ -668,20 +668,6 @@ _term_it_save(u3_noun pax, u3_noun pad) free(pax_c); } -/* _term_io_flow(): send flow. -*/ -static void -_term_io_flow(u3_utty* uty_u) -{ - u3_noun tid = u3dc("scot", c3__ud, uty_u->tid_l); - u3_noun pax = u3nq(u3_blip, c3__term, tid, u3_nul); - - u3v_plan(pax, u3nq(c3__flow, c3__seat, c3__talk, u3_nul)); - // u3v_plan(pax, u3nt(c3__flow, c3__seat, u3_nul)); - // u3v_plan(pax, u3nq(c3__flow, c3__seat, c3__dojo, u3_nul)); - // u3v_plan(pax, u3nq(c3__flow, c3__seat, c3__helm, u3_nul)); -} - /* _term_io_belt(): send belt. */ static void From 8f23a0f9437ccbbb5302ab4803103f11b6a105a6 Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Thu, 30 Apr 2015 17:13:23 -0700 Subject: [PATCH 16/24] Reenable optimization in master. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f6042e2e0..c83c8a0d7 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ MDEFINES=-DU3_OS_$(OS) -DU3_OS_ENDIAN_$(ENDIAN) -D U3_LIB=\"$(LIB)\" # NOTFORCHECKIN - restore -O3 # -DGHETTO -CFLAGS= $(COSFLAGS) -g -msse3 -ffast-math \ +CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ -funsigned-char \ -I/usr/local/include \ -I/opt/local/include \ From 0385e3a701e2aca5986f97d60b9ae489edeb2072 Mon Sep 17 00:00:00 2001 From: Max G Date: Sun, 3 May 2015 15:26:42 +0300 Subject: [PATCH 17/24] Jetted scrypt --- Makefile | 22 +- i/j/q.h | 6 + i/j/w.h | 5 + j/e/scr.c | 232 ++++++++++++++++ j/tree.c | 14 + outside/scrypt/Makefile | 16 ++ outside/scrypt/crypto_scrypt-sse.c | 357 +++++++++++++++++++++++++ outside/scrypt/crypto_scrypt.h | 51 ++++ outside/scrypt/scrypt.a | Bin 0 -> 82332 bytes outside/scrypt/sha256.c | 411 +++++++++++++++++++++++++++++ outside/scrypt/sha256.h | 62 +++++ outside/scrypt/sysendian.h | 129 +++++++++ 12 files changed, 1298 insertions(+), 7 deletions(-) create mode 100644 j/e/scr.c create mode 100644 outside/scrypt/Makefile create mode 100644 outside/scrypt/crypto_scrypt-sse.c create mode 100644 outside/scrypt/crypto_scrypt.h create mode 100644 outside/scrypt/scrypt.a create mode 100644 outside/scrypt/sha256.c create mode 100644 outside/scrypt/sha256.h create mode 100644 outside/scrypt/sysendian.h diff --git a/Makefile b/Makefile index c83c8a0d7..5b94668d0 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ RM=rm -f CC=gcc CXX=g++ CXXFLAGS=$(CFLAGS) -CLD=g++ -g -L/usr/local/lib -L/opt/local/lib +CLD=g++ -L/usr/local/lib -L/opt/local/lib ifeq ($(OS),osx) COSFLAGS=-fno-diagnostics-fixit-info @@ -78,6 +78,7 @@ CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ -Ioutside/ed25519/src \ -Ioutside/commonmark/src \ -Ioutside/commonmark/build/src \ + -Ioutside/scrypt \ $(DEFINES) \ $(MDEFINES) @@ -201,6 +202,7 @@ J_E_OFILES=\ j/e/repg.o \ j/e/rexp.o \ j/e/rub.o \ + j/e/scr.o \ j/e/shax.o \ j/e/lore.o \ j/e/loss.o \ @@ -350,6 +352,8 @@ LIBANACHRONISM=outside/anachronism/build/libanachronism.a LIBCOMMONMARK=outside/commonmark/build/src/libcmark.a +LIBSCRYPT=outside/scrypt/scrypt.a + all: vere .MAKEFILE-VERSION: Makefile .make.conf @@ -380,25 +384,28 @@ $(LIBANACHRONISM): $(LIBCOMMONMARK): $(MAKE) -C outside/commonmark +$(LIBSCRYPT): + $(MAKE) -C outside/scrypt MDEFINES="$(MDEFINES)" + $(CRE2_OFILES): outside/cre2/src/src/cre2.cpp outside/cre2/src/src/cre2.h $(LIBRE2) $(CXX) $(CXXFLAGS) -c $< -o $@ $(V_OFILES): i/v/vere.h ifdef NO_SILENT_RULES -$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) +$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) mkdir -p $(BIN) - $(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) + $(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) else -$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) +$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) @echo " CCLD $(BIN)/vere" @mkdir -p $(BIN) - @$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) + @$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) endif -$(BIN)/meme: $(LIBCRE) $(LIBCOMMONMARK) $(MEME_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) +$(BIN)/meme: $(LIBCRE) $(LIBCOMMONMARK) $(MEME_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) mkdir -p $(BIN) - $(CLD) $(CLDOSFLAGS) -o $(BIN)/meme $(MEME_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) + $(CLD) $(CLDOSFLAGS) -o $(BIN)/meme $(MEME_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) tags: ctags -R -f .tags --exclude=root @@ -433,5 +440,6 @@ distclean: clean $(LIBUV_MAKEFILE) $(MAKE) -C outside/re2 clean $(MAKE) -C outside/ed25519 clean $(MAKE) -C outside/anachronism clean + $(MAKE) -C outside/scrypt clean .PHONY: clean debbuild debinstalldistclean etags osxpackage tags diff --git a/i/j/q.h b/i/j/q.h index 9d490f6d2..04a636295 100644 --- a/i/j/q.h +++ b/i/j/q.h @@ -93,6 +93,12 @@ u3_noun u3qea_de(u3_atom, u3_atom); u3_noun u3qea_en(u3_atom, u3_atom); + u3_noun u3qes_hsh(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, u3_atom); + u3_noun u3qes_hsl(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, + u3_atom, u3_atom, u3_atom); + u3_noun u3qes_pbk(u3_atom, u3_atom, u3_atom, u3_atom); + u3_noun u3qes_pbl(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, u3_atom); + u3_noun u3qe_shax(u3_atom); u3_noun u3qe_shay(u3_atom, u3_atom); u3_noun u3qe_shas(u3_atom, u3_atom); diff --git a/i/j/w.h b/i/j/w.h index 615f237c9..1ebb5f286 100644 --- a/i/j/w.h +++ b/i/j/w.h @@ -105,6 +105,11 @@ u3_noun u3wea_de(u3_noun); u3_noun u3wea_en(u3_noun); + u3_noun u3wes_hsh(u3_noun); + u3_noun u3wes_hsl(u3_noun); + u3_noun u3wes_pbk(u3_noun); + u3_noun u3wes_pbl(u3_noun); + u3_noun u3we_shax(u3_noun); u3_noun u3we_shay(u3_noun); u3_noun u3we_shas(u3_noun); diff --git a/j/e/scr.c b/j/e/scr.c new file mode 100644 index 000000000..3d6a87978 --- /dev/null +++ b/j/e/scr.c @@ -0,0 +1,232 @@ +/* j/5/scr.c +** +*/ +#include "all.h" + +#include +#include +#include + +int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, + uint64_t, uint32_t, uint32_t, uint8_t *, size_t); + +/* functions +*/ + + u3_noun + u3qes_hsl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, u3_atom n, + u3_atom r, u3_atom z, u3_atom d) + { + c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && + _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && + _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && + (r * z) < 1073741824); + + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + _crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_hsl(u3_noun cor) + { + u3_noun p, pl, s, sl, n, r, z, d; + u3_noun q; + + u3x_quil(u3r_at(u3x_sam, cor), &p, &pl, &s, &sl, &q); + u3x_qual(q, &n, &r, &z, &d); + + return u3qes_hsl(p, pl, s, sl, n, r, z, d); + } + + u3_noun + u3qes_hsh(u3_atom p, u3_atom s, u3_atom n, u3_atom r, u3_atom z, u3_atom d) + { + c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && + _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && + (r * z) < 1073741824); + + c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + _crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_hsh(u3_noun cor) + { + u3_noun p, s, n, r, z, d; + u3_noun q; + + u3x_quil(u3r_at(u3x_sam, cor), &p, &s, &n, &r, &q); + u3x_cell(q, &z, &d); + + return u3qes_hsh(p, s, n, r, z, d); + } + + u3_noun + u3qes_pbl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, + u3_atom c, u3_atom d) + { + c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && + _(u3a_is_cat(c)) && _(u3a_is_cat(d))); + + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + PBKDF2_SHA256(b_p, pl, b_s, sl, c, buf, d); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_pbl(u3_noun cor) + { + u3_noun p, pl, s, sl, c, d; + u3_noun q; + + u3x_quil(u3r_at(u3x_sam, cor), &p, &pl, &s, &sl, &q); + u3x_cell(q, &c, &d); + + return u3qes_pbl(p, pl, s, sl, c, d); + } + + u3_noun + u3qes_pbk(u3_atom p, u3_atom s, u3_atom c, u3_atom d) + { + c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(c)) && _(u3a_is_cat(d))); + + c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + PBKDF2_SHA256(b_p, pl, b_s, sl, c, buf, d); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_pbk(u3_noun cor) + { + u3_noun p, s, c, d; + + u3x_qual(u3r_at(u3x_sam, cor), &p, &s, &c, &d); + + return u3qes_pbk(p, s, c, d); + } + + +/** + * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): + * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, + * p, buflen) and write the result into buf. The parameters r, p, and buflen + * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N + * must be a power of 2 greater than 1. + * + * Return 0 on success; or -1 on error. + */ +int +_crypto_scrypt(const uint8_t * passwd, size_t passwdlen, + const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, + uint8_t * buf, size_t buflen) +{ + void * B0, * V0, * XY0; + uint8_t * B; + uint32_t * V; + uint32_t * XY; + uint32_t i; + + /* Sanity-check parameters. */ +#if SIZE_MAX > UINT32_MAX + if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { + errno = EFBIG; + goto err0; + } +#endif + if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { + errno = EFBIG; + goto err0; + } + if (((N & (N - 1)) != 0) || (N == 0)) { + errno = EINVAL; + goto err0; + } + if ((r > SIZE_MAX / 128 / p) || +#if SIZE_MAX / 256 <= UINT32_MAX + (r > (SIZE_MAX - 64) / 256) || +#endif + (N > SIZE_MAX / 128 / r)) { + errno = ENOMEM; + goto err0; + } + + /* Allocate memory. */ + if ((B0 = u3a_malloc(128 * r * p + 63)) == NULL) + goto err0; + B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63)); + if ((XY0 = u3a_malloc(256 * r + 64 + 63)) == NULL) + goto err1; + XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63)); + if ((V0 = u3a_malloc(128 * r * N + 63)) == NULL) + goto err2; + V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63)); + + /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */ + PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r); + + /* 2: for i = 0 to p - 1 do */ + for (i = 0; i < p; i++) { + /* 3: B_i <-- MF(B_i, N) */ + smix(&B[i * 128 * r], r, N, V, XY); + } + + /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */ + PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen); + + /* Free memory. */ + + u3a_free(V0); + u3a_free(XY0); + u3a_free(B0); + + /* Success! */ + return (0); + +err2: + u3a_free(XY0); +err1: + u3a_free(B0); +err0: + /* Failure! */ + return (-1); +} diff --git a/j/tree.c b/j/tree.c index ae778d98c..6c0ff2b46 100644 --- a/j/tree.c +++ b/j/tree.c @@ -231,6 +231,18 @@ static u3j_core _mood__hoon__coed_d[] = {} }; +static u3j_harm _mood__hoon__scr_hsh_a[] = {{".2", u3wes_hsh}, {}}; +static u3j_harm _mood__hoon__scr_hsl_a[] = {{".2", u3wes_hsl}, {}}; +static u3j_harm _mood__hoon__scr_pbk_a[] = {{".2", u3wes_pbk}, {}}; +static u3j_harm _mood__hoon__scr_pbl_a[] = {{".2", u3wes_pbl}, {}}; +static u3j_core _mood__hoon__scr_d[] = + { { "hsh", _mood__hoon__scr_hsh_a }, + { "hsl", _mood__hoon__scr_hsl_a }, + { "pbk", _mood__hoon__scr_pbk_a }, + { "pbl", _mood__hoon__scr_pbl_a }, + {} + }; + static u3j_harm _mood__hoon_pfix_a[] = {{".2", u3we_pfix}, {}}; static u3j_harm _mood__hoon_plug_a[] = {{".2", u3we_plug}, {}}; static u3j_harm _mood__hoon_pose_a[] = {{".2", u3we_pose}, {}}; @@ -449,6 +461,8 @@ static u3j_core _mood__hoon_d[] = { "rd", 0, _mood__hoon__rd_d }, { "coed", 0, _mood__hoon__coed_d }, + { "scr", 0, _mood__hoon__scr_d }, + { "pfix", _mood__hoon_pfix_a }, { "plug", _mood__hoon_plug_a }, { "pose", _mood__hoon_pose_a }, diff --git a/outside/scrypt/Makefile b/outside/scrypt/Makefile new file mode 100644 index 000000000..f3ac5acb9 --- /dev/null +++ b/outside/scrypt/Makefile @@ -0,0 +1,16 @@ +default: all + +CC?=gcc +CFLAGS?=-O2 -msse3 -ffast-math \ + -Wall -g -D_FORTIFY_SOURCE=2 -fPIC +CFLAGS_EXTRA?=-Wl,-rpath=. + +all: scrypt.a + +OBJS= crypto_scrypt-sse.o sha256.o + +scrypt.a: $(OBJS) + ar rcs scrypt.a $(OBJS) + +clean: + rm -f *.o scrypt.a diff --git a/outside/scrypt/crypto_scrypt-sse.c b/outside/scrypt/crypto_scrypt-sse.c new file mode 100644 index 000000000..d7b33c078 --- /dev/null +++ b/outside/scrypt/crypto_scrypt-sse.c @@ -0,0 +1,357 @@ +/*- + * Copyright 2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ +#include +#include + +#include +#include +#include +#include +#include + +#include "sha256.h" +#include "sysendian.h" + +#include "crypto_scrypt.h" + +static void +blkcpy(void * dest, void * src, size_t len) +{ + __m128i * D = dest; + __m128i * S = src; + size_t L = len / 16; + size_t i; + + for (i = 0; i < L; i++) + D[i] = S[i]; +} + +static void +blkxor(void * dest, void * src, size_t len) +{ + __m128i * D = dest; + __m128i * S = src; + size_t L = len / 16; + size_t i; + + for (i = 0; i < L; i++) + D[i] = _mm_xor_si128(D[i], S[i]); +} + +/** + * salsa20_8(B): + * Apply the salsa20/8 core to the provided block. + */ +static void +salsa20_8(__m128i B[4]) +{ + __m128i X0, X1, X2, X3; + __m128i T; + size_t i; + + X0 = B[0]; + X1 = B[1]; + X2 = B[2]; + X3 = B[3]; + + for (i = 0; i < 8; i += 2) { + /* Operate on "columns". */ + T = _mm_add_epi32(X0, X3); + X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 7)); + X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 25)); + T = _mm_add_epi32(X1, X0); + X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9)); + X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23)); + T = _mm_add_epi32(X2, X1); + X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 13)); + X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 19)); + T = _mm_add_epi32(X3, X2); + X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18)); + X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14)); + + /* Rearrange data. */ + X1 = _mm_shuffle_epi32(X1, 0x93); + X2 = _mm_shuffle_epi32(X2, 0x4E); + X3 = _mm_shuffle_epi32(X3, 0x39); + + /* Operate on "rows". */ + T = _mm_add_epi32(X0, X1); + X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 7)); + X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 25)); + T = _mm_add_epi32(X3, X0); + X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9)); + X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23)); + T = _mm_add_epi32(X2, X3); + X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 13)); + X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 19)); + T = _mm_add_epi32(X1, X2); + X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18)); + X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14)); + + /* Rearrange data. */ + X1 = _mm_shuffle_epi32(X1, 0x39); + X2 = _mm_shuffle_epi32(X2, 0x4E); + X3 = _mm_shuffle_epi32(X3, 0x93); + } + + B[0] = _mm_add_epi32(B[0], X0); + B[1] = _mm_add_epi32(B[1], X1); + B[2] = _mm_add_epi32(B[2], X2); + B[3] = _mm_add_epi32(B[3], X3); +} + +/** + * blockmix_salsa8(Bin, Bout, X, r): + * Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r + * bytes in length; the output Bout must also be the same size. The + * temporary space X must be 64 bytes. + */ +static void +blockmix_salsa8(__m128i * Bin, __m128i * Bout, __m128i * X, size_t r) +{ + size_t i; + + /* 1: X <-- B_{2r - 1} */ + blkcpy(X, &Bin[8 * r - 4], 64); + + /* 2: for i = 0 to 2r - 1 do */ + for (i = 0; i < r; i++) { + /* 3: X <-- H(X \xor B_i) */ + blkxor(X, &Bin[i * 8], 64); + salsa20_8(X); + + /* 4: Y_i <-- X */ + /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ + blkcpy(&Bout[i * 4], X, 64); + + /* 3: X <-- H(X \xor B_i) */ + blkxor(X, &Bin[i * 8 + 4], 64); + salsa20_8(X); + + /* 4: Y_i <-- X */ + /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ + blkcpy(&Bout[(r + i) * 4], X, 64); + } +} + +/** + * integerify(B, r): + * Return the result of parsing B_{2r-1} as a little-endian integer. + */ +static uint64_t +integerify(void * B, size_t r) +{ + uint32_t * X = (void *)((uintptr_t)(B) + (2 * r - 1) * 64); + + return (((uint64_t)(X[13]) << 32) + X[0]); +} + +/** + * smix(B, r, N, V, XY): + * Compute B = SMix_r(B, N). The input B must be 128r bytes in length; + * the temporary storage V must be 128rN bytes in length; the temporary + * storage XY must be 256r + 64 bytes in length. The value N must be a + * power of 2 greater than 1. The arrays B, V, and XY must be aligned to a + * multiple of 64 bytes. + */ +void +smix(uint8_t * B, size_t r, uint64_t N, void * V, void * XY) +{ + __m128i * X = XY; + __m128i * Y = (void *)((uintptr_t)(XY) + 128 * r); + __m128i * Z = (void *)((uintptr_t)(XY) + 256 * r); + uint32_t * X32 = (void *)X; + uint64_t i, j; + size_t k; + + /* 1: X <-- B */ + for (k = 0; k < 2 * r; k++) { + for (i = 0; i < 16; i++) { + X32[k * 16 + i] = + le32dec(&B[(k * 16 + (i * 5 % 16)) * 4]); + } + } + + /* 2: for i = 0 to N - 1 do */ + for (i = 0; i < N; i += 2) { + /* 3: V_i <-- X */ + blkcpy((void *)((uintptr_t)(V) + i * 128 * r), X, 128 * r); + + /* 4: X <-- H(X) */ + blockmix_salsa8(X, Y, Z, r); + + /* 3: V_i <-- X */ + blkcpy((void *)((uintptr_t)(V) + (i + 1) * 128 * r), + Y, 128 * r); + + /* 4: X <-- H(X) */ + blockmix_salsa8(Y, X, Z, r); + } + + /* 6: for i = 0 to N - 1 do */ + for (i = 0; i < N; i += 2) { + /* 7: j <-- Integerify(X) mod N */ + j = integerify(X, r) & (N - 1); + + /* 8: X <-- H(X \xor V_j) */ + blkxor(X, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r); + blockmix_salsa8(X, Y, Z, r); + + /* 7: j <-- Integerify(X) mod N */ + j = integerify(Y, r) & (N - 1); + + /* 8: X <-- H(X \xor V_j) */ + blkxor(Y, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r); + blockmix_salsa8(Y, X, Z, r); + } + + /* 10: B' <-- X */ + for (k = 0; k < 2 * r; k++) { + for (i = 0; i < 16; i++) { + le32enc(&B[(k * 16 + (i * 5 % 16)) * 4], + X32[k * 16 + i]); + } + } +} + +/** + * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): + * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, + * p, buflen) and write the result into buf. The parameters r, p, and buflen + * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N + * must be a power of 2 greater than 1. + * + * Return 0 on success; or -1 on error. + */ +int +crypto_scrypt(const uint8_t * passwd, size_t passwdlen, + const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, + uint8_t * buf, size_t buflen) +{ + void * B0, * V0, * XY0; + uint8_t * B; + uint32_t * V; + uint32_t * XY; + uint32_t i; + + /* Sanity-check parameters. */ +#if SIZE_MAX > UINT32_MAX + if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { + errno = EFBIG; + goto err0; + } +#endif + if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { + errno = EFBIG; + goto err0; + } + if (((N & (N - 1)) != 0) || (N == 0)) { + errno = EINVAL; + goto err0; + } + if ((r > SIZE_MAX / 128 / p) || +#if SIZE_MAX / 256 <= UINT32_MAX + (r > (SIZE_MAX - 64) / 256) || +#endif + (N > SIZE_MAX / 128 / r)) { + errno = ENOMEM; + goto err0; + } + + /* Allocate memory. */ +#ifdef HAVE_POSIX_MEMALIGN + if ((errno = posix_memalign(&B0, 64, 128 * r * p)) != 0) + goto err0; + B = (uint8_t *)(B0); + if ((errno = posix_memalign(&XY0, 64, 256 * r + 64)) != 0) + goto err1; + XY = (uint32_t *)(XY0); +#ifndef MAP_ANON + if ((errno = posix_memalign(&V0, 64, 128 * r * N)) != 0) + goto err2; + V = (uint32_t *)(V0); +#endif +#else + if ((B0 = malloc(128 * r * p + 63)) == NULL) + goto err0; + B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63)); + if ((XY0 = malloc(256 * r + 64 + 63)) == NULL) + goto err1; + XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63)); +#ifndef MAP_ANON + if ((V0 = malloc(128 * r * N + 63)) == NULL) + goto err2; + V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63)); +#endif +#endif +#ifdef MAP_ANON + if ((V0 = mmap(NULL, 128 * r * N, PROT_READ | PROT_WRITE, +#ifdef MAP_NOCORE + MAP_ANON | MAP_PRIVATE | MAP_NOCORE, +#else + MAP_ANON | MAP_PRIVATE, +#endif + -1, 0)) == MAP_FAILED) + goto err2; + V = (uint32_t *)(V0); +#endif + + /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */ + PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r); + + /* 2: for i = 0 to p - 1 do */ + for (i = 0; i < p; i++) { + /* 3: B_i <-- MF(B_i, N) */ + smix(&B[i * 128 * r], r, N, V, XY); + } + + /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */ + PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen); + + /* Free memory. */ +#ifdef MAP_ANON + if (munmap(V0, 128 * r * N)) + goto err2; +#else + free(V0); +#endif + free(XY0); + free(B0); + + /* Success! */ + return (0); + +err2: + free(XY0); +err1: + free(B0); +err0: + /* Failure! */ + return (-1); +} diff --git a/outside/scrypt/crypto_scrypt.h b/outside/scrypt/crypto_scrypt.h new file mode 100644 index 000000000..b88be09d8 --- /dev/null +++ b/outside/scrypt/crypto_scrypt.h @@ -0,0 +1,51 @@ +/*- + * Copyright 2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ +#ifndef _CRYPTO_SCRYPT_H_ +#define _CRYPTO_SCRYPT_H_ + +#include +#include + +void smix(uint8_t *, size_t, uint64_t, void *, void *); +void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, + uint64_t, uint8_t *, size_t); + +/** + * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): + * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, + * p, buflen) and write the result into buf. The parameters r, p, and buflen + * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N + * must be a power of 2 greater than 1. + * + * Return 0 on success; or -1 on error. + */ +int crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t, + uint32_t, uint32_t, uint8_t *, size_t); + +#endif /* !_CRYPTO_SCRYPT_H_ */ diff --git a/outside/scrypt/scrypt.a b/outside/scrypt/scrypt.a new file mode 100644 index 0000000000000000000000000000000000000000..94106a866015690695216eabe99dd40198d7363f GIT binary patch literal 82332 zcmc$H30zfW`u{oiAYMcP#SKNh=*^`RxNd1`a`B=UMFmC0aY1Ae5`nnjk_sAH-i(r# z8JjGenHHy<$(p9ArUkUza!gyCwkcb+Y|$*U)&KLn=XuUOy!T$CneP90K5)y!q~jZ{NgLyCD~eTj^V?SM~)bA`G}!5Te8S9|JrPhkt32}r5II|?lXLJiXc;zu1c&@y8l=64g$_afD^UQwGz|-#>4a>}!2cYuz7Jf-4K9;WAO{2rStbU_s8@jDJ&^FO zAptEqaI4VM0rjA7ZwWoF=!%zRn@r|F_Cd6-{0(6l5a4zByU`n;`RT$1z<+AOpYQPJ z3~2mUQFLuv_=mtp*J8|Trzh_zf-Nz+&jwLT&N*)Hes}Znw$9nkSU-QJho z_1SHk98K=JPpu$7%mO9DGF)Lr+ynqK$Cy7aoeDH)?bjNVv&;lc%X-E-D?3!L+v3!Dp`xqHyx(^I{BbeE@k z_c~{#d%p(b+o1D5xV`&krPmLJUafxN_MUY&zi)*YqdkhqGd)L^ljtg$J$?dJO z+uYu4dv~`t!=CK+&bN<3u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d3ecArmfbEzsdd|$Ra(WAuMm_6=p94QDybrup{5ie< zuG3pSxj25iMbG8+odjfH%z_~y4qt2=5BJsaJ z-vys_;M8A-evj~b;5EWIQUAPf&d0wDZfRMbBjKO5o1*9a#vakH#Cr8PZgu#L{9ik6 z{uiJhcHH#&W#LEIMjbc(@`wh(7spNi0Qzr^n|>PlNykk;1O2S# z;0edg|7$D@Qo@U|UK@p9!~S37xcPsE|31gfKMjArj)VCW9FBkJaC-A;0>9$8`LrYM zZO2VN0R4S%?pK^}`pD_6RKMWU@3{Hwtq4EDHYB_b{JrDeXUuW)p?(6K`EbJOPp3DZ zov8Dy|NHwteDKLgIV1Bg2+{0I1A9Dvl9;lAy9;e4>8 zSa=3}8icdXmxLdI{;BYj;GcvygU<+0rGlt!$&SA*f8T%J0nYQ@P%H~7gl|Xv(XEd5 zD|GRqC01ZL)(8Iv0}JpZxY@!wBIwpc%sB5$RI7e<40?of{5US0{nDf*7&gY`^_TYp N$$1^D7Cq1Z{{a2a0Hgo_ literal 0 HcmV?d00001 diff --git a/outside/scrypt/sha256.c b/outside/scrypt/sha256.c new file mode 100644 index 000000000..d2f915f1a --- /dev/null +++ b/outside/scrypt/sha256.c @@ -0,0 +1,411 @@ +/*- + * Copyright 2005,2007,2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +#include "sysendian.h" + +#include "sha256.h" + +/* + * Encode a length len/4 vector of (uint32_t) into a length len vector of + * (unsigned char) in big-endian form. Assumes len is a multiple of 4. + */ +static void +be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len) +{ + size_t i; + + for (i = 0; i < len / 4; i++) + be32enc(dst + i * 4, src[i]); +} + +/* + * Decode a big-endian length len vector of (unsigned char) into a length + * len/4 vector of (uint32_t). Assumes len is a multiple of 4. + */ +static void +be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len) +{ + size_t i; + + for (i = 0; i < len / 4; i++) + dst[i] = be32dec(src + i * 4); +} + +/* Elementary functions used by SHA256 */ +#define Ch(x, y, z) ((x & (y ^ z)) ^ z) +#define Maj(x, y, z) ((x & (y | z)) | (y & z)) +#define SHR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << (32 - n))) +#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) + +/* SHA256 round function */ +#define RND(a, b, c, d, e, f, g, h, k) \ + t0 = h + S1(e) + Ch(e, f, g) + k; \ + t1 = S0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +/* Adjusted round function for rotating state */ +#define RNDr(S, W, i, k) \ + RND(S[(64 - i) % 8], S[(65 - i) % 8], \ + S[(66 - i) % 8], S[(67 - i) % 8], \ + S[(68 - i) % 8], S[(69 - i) % 8], \ + S[(70 - i) % 8], S[(71 - i) % 8], \ + W[i] + k) + +/* + * SHA256 block compression function. The 256-bit state is transformed via + * the 512-bit input block to produce a new state. + */ +static void +SHA256_Transform(uint32_t * state, const unsigned char block[64]) +{ + uint32_t W[64]; + uint32_t S[8]; + uint32_t t0, t1; + int i; + + /* 1. Prepare message schedule W. */ + be32dec_vect(W, block, 64); + for (i = 16; i < 64; i++) + W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; + + /* 2. Initialize working variables. */ + memcpy(S, state, 32); + + /* 3. Mix. */ + RNDr(S, W, 0, 0x428a2f98); + RNDr(S, W, 1, 0x71374491); + RNDr(S, W, 2, 0xb5c0fbcf); + RNDr(S, W, 3, 0xe9b5dba5); + RNDr(S, W, 4, 0x3956c25b); + RNDr(S, W, 5, 0x59f111f1); + RNDr(S, W, 6, 0x923f82a4); + RNDr(S, W, 7, 0xab1c5ed5); + RNDr(S, W, 8, 0xd807aa98); + RNDr(S, W, 9, 0x12835b01); + RNDr(S, W, 10, 0x243185be); + RNDr(S, W, 11, 0x550c7dc3); + RNDr(S, W, 12, 0x72be5d74); + RNDr(S, W, 13, 0x80deb1fe); + RNDr(S, W, 14, 0x9bdc06a7); + RNDr(S, W, 15, 0xc19bf174); + RNDr(S, W, 16, 0xe49b69c1); + RNDr(S, W, 17, 0xefbe4786); + RNDr(S, W, 18, 0x0fc19dc6); + RNDr(S, W, 19, 0x240ca1cc); + RNDr(S, W, 20, 0x2de92c6f); + RNDr(S, W, 21, 0x4a7484aa); + RNDr(S, W, 22, 0x5cb0a9dc); + RNDr(S, W, 23, 0x76f988da); + RNDr(S, W, 24, 0x983e5152); + RNDr(S, W, 25, 0xa831c66d); + RNDr(S, W, 26, 0xb00327c8); + RNDr(S, W, 27, 0xbf597fc7); + RNDr(S, W, 28, 0xc6e00bf3); + RNDr(S, W, 29, 0xd5a79147); + RNDr(S, W, 30, 0x06ca6351); + RNDr(S, W, 31, 0x14292967); + RNDr(S, W, 32, 0x27b70a85); + RNDr(S, W, 33, 0x2e1b2138); + RNDr(S, W, 34, 0x4d2c6dfc); + RNDr(S, W, 35, 0x53380d13); + RNDr(S, W, 36, 0x650a7354); + RNDr(S, W, 37, 0x766a0abb); + RNDr(S, W, 38, 0x81c2c92e); + RNDr(S, W, 39, 0x92722c85); + RNDr(S, W, 40, 0xa2bfe8a1); + RNDr(S, W, 41, 0xa81a664b); + RNDr(S, W, 42, 0xc24b8b70); + RNDr(S, W, 43, 0xc76c51a3); + RNDr(S, W, 44, 0xd192e819); + RNDr(S, W, 45, 0xd6990624); + RNDr(S, W, 46, 0xf40e3585); + RNDr(S, W, 47, 0x106aa070); + RNDr(S, W, 48, 0x19a4c116); + RNDr(S, W, 49, 0x1e376c08); + RNDr(S, W, 50, 0x2748774c); + RNDr(S, W, 51, 0x34b0bcb5); + RNDr(S, W, 52, 0x391c0cb3); + RNDr(S, W, 53, 0x4ed8aa4a); + RNDr(S, W, 54, 0x5b9cca4f); + RNDr(S, W, 55, 0x682e6ff3); + RNDr(S, W, 56, 0x748f82ee); + RNDr(S, W, 57, 0x78a5636f); + RNDr(S, W, 58, 0x84c87814); + RNDr(S, W, 59, 0x8cc70208); + RNDr(S, W, 60, 0x90befffa); + RNDr(S, W, 61, 0xa4506ceb); + RNDr(S, W, 62, 0xbef9a3f7); + RNDr(S, W, 63, 0xc67178f2); + + /* 4. Mix local working variables into global state */ + for (i = 0; i < 8; i++) + state[i] += S[i]; + + /* Clean the stack. */ + memset(W, 0, 256); + memset(S, 0, 32); + t0 = t1 = 0; +} + +static unsigned char PAD[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* Add padding and terminating bit-count. */ +static void +SHA256_Pad(SHA256_CTX * ctx) +{ + unsigned char len[8]; + uint32_t r, plen; + + /* + * Convert length to a vector of bytes -- we do this now rather + * than later because the length will change after we pad. + */ + be32enc_vect(len, ctx->count, 8); + + /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ + r = (ctx->count[1] >> 3) & 0x3f; + plen = (r < 56) ? (56 - r) : (120 - r); + SHA256_Update(ctx, PAD, (size_t)plen); + + /* Add the terminating bit-count */ + SHA256_Update(ctx, len, 8); +} + +/* SHA-256 initialization. Begins a SHA-256 operation. */ +void +SHA256_Init(SHA256_CTX * ctx) +{ + + /* Zero bits processed so far */ + ctx->count[0] = ctx->count[1] = 0; + + /* Magic initialization constants */ + ctx->state[0] = 0x6A09E667; + ctx->state[1] = 0xBB67AE85; + ctx->state[2] = 0x3C6EF372; + ctx->state[3] = 0xA54FF53A; + ctx->state[4] = 0x510E527F; + ctx->state[5] = 0x9B05688C; + ctx->state[6] = 0x1F83D9AB; + ctx->state[7] = 0x5BE0CD19; +} + +/* Add bytes into the hash */ +void +SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) +{ + uint32_t bitlen[2]; + uint32_t r; + const unsigned char *src = in; + + /* Number of bytes left in the buffer from previous updates */ + r = (ctx->count[1] >> 3) & 0x3f; + + /* Convert the length into a number of bits */ + bitlen[1] = ((uint32_t)len) << 3; + bitlen[0] = (uint32_t)(len >> 29); + + /* Update number of bits */ + if ((ctx->count[1] += bitlen[1]) < bitlen[1]) + ctx->count[0]++; + ctx->count[0] += bitlen[0]; + + /* Handle the case where we don't need to perform any transforms */ + if (len < 64 - r) { + memcpy(&ctx->buf[r], src, len); + return; + } + + /* Finish the current block */ + memcpy(&ctx->buf[r], src, 64 - r); + SHA256_Transform(ctx->state, ctx->buf); + src += 64 - r; + len -= 64 - r; + + /* Perform complete blocks */ + while (len >= 64) { + SHA256_Transform(ctx->state, src); + src += 64; + len -= 64; + } + + /* Copy left over data into buffer */ + memcpy(ctx->buf, src, len); +} + +/* + * SHA-256 finalization. Pads the input data, exports the hash value, + * and clears the context state. + */ +void +SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx) +{ + + /* Add padding */ + SHA256_Pad(ctx); + + /* Write the hash */ + be32enc_vect(digest, ctx->state, 32); + + /* Clear the context state */ + memset((void *)ctx, 0, sizeof(*ctx)); +} + +/* Initialize an HMAC-SHA256 operation with the given key. */ +void +HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen) +{ + unsigned char pad[64]; + unsigned char khash[32]; + const unsigned char * K = _K; + size_t i; + + /* If Klen > 64, the key is really SHA256(K). */ + if (Klen > 64) { + SHA256_Init(&ctx->ictx); + SHA256_Update(&ctx->ictx, K, Klen); + SHA256_Final(khash, &ctx->ictx); + K = khash; + Klen = 32; + } + + /* Inner SHA256 operation is SHA256(K xor [block of 0x36] || data). */ + SHA256_Init(&ctx->ictx); + memset(pad, 0x36, 64); + for (i = 0; i < Klen; i++) + pad[i] ^= K[i]; + SHA256_Update(&ctx->ictx, pad, 64); + + /* Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash). */ + SHA256_Init(&ctx->octx); + memset(pad, 0x5c, 64); + for (i = 0; i < Klen; i++) + pad[i] ^= K[i]; + SHA256_Update(&ctx->octx, pad, 64); + + /* Clean the stack. */ + memset(khash, 0, 32); +} + +/* Add bytes to the HMAC-SHA256 operation. */ +void +HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void *in, size_t len) +{ + + /* Feed data to the inner SHA256 operation. */ + SHA256_Update(&ctx->ictx, in, len); +} + +/* Finish an HMAC-SHA256 operation. */ +void +HMAC_SHA256_Final(unsigned char digest[32], HMAC_SHA256_CTX * ctx) +{ + unsigned char ihash[32]; + + /* Finish the inner SHA256 operation. */ + SHA256_Final(ihash, &ctx->ictx); + + /* Feed the inner hash to the outer SHA256 operation. */ + SHA256_Update(&ctx->octx, ihash, 32); + + /* Finish the outer SHA256 operation. */ + SHA256_Final(digest, &ctx->octx); + + /* Clean the stack. */ + memset(ihash, 0, 32); +} + +/** + * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): + * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and + * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). + */ +void +PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, + size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen) +{ + HMAC_SHA256_CTX PShctx, hctx; + size_t i; + uint8_t ivec[4]; + uint8_t U[32]; + uint8_t T[32]; + uint64_t j; + int k; + size_t clen; + + /* Compute HMAC state after processing P and S. */ + HMAC_SHA256_Init(&PShctx, passwd, passwdlen); + HMAC_SHA256_Update(&PShctx, salt, saltlen); + + /* Iterate through the blocks. */ + for (i = 0; i * 32 < dkLen; i++) { + /* Generate INT(i + 1). */ + be32enc(ivec, (uint32_t)(i + 1)); + + /* Compute U_1 = PRF(P, S || INT(i)). */ + memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX)); + HMAC_SHA256_Update(&hctx, ivec, 4); + HMAC_SHA256_Final(U, &hctx); + + /* T_i = U_1 ... */ + memcpy(T, U, 32); + + for (j = 2; j <= c; j++) { + /* Compute U_j. */ + HMAC_SHA256_Init(&hctx, passwd, passwdlen); + HMAC_SHA256_Update(&hctx, U, 32); + HMAC_SHA256_Final(U, &hctx); + + /* ... xor U_j ... */ + for (k = 0; k < 32; k++) + T[k] ^= U[k]; + } + + /* Copy as many bytes as necessary into buf. */ + clen = dkLen - i * 32; + if (clen > 32) + clen = 32; + memcpy(&buf[i * 32], T, clen); + } + + /* Clean PShctx, since we never called _Final on it. */ + memset(&PShctx, 0, sizeof(HMAC_SHA256_CTX)); +} diff --git a/outside/scrypt/sha256.h b/outside/scrypt/sha256.h new file mode 100644 index 000000000..289a5232f --- /dev/null +++ b/outside/scrypt/sha256.h @@ -0,0 +1,62 @@ +/*- + * Copyright 2005,2007,2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/libmd/sha256.h,v 1.2 2006/01/17 15:35:56 phk Exp $ + */ + +#ifndef _SHA256_H_ +#define _SHA256_H_ + +#include + +#include + +typedef struct SHA256Context { + uint32_t state[8]; + uint32_t count[2]; + unsigned char buf[64]; +} SHA256_CTX; + +typedef struct HMAC_SHA256Context { + SHA256_CTX ictx; + SHA256_CTX octx; +} HMAC_SHA256_CTX; + +void SHA256_Init(SHA256_CTX *); +void SHA256_Update(SHA256_CTX *, const void *, size_t); +void SHA256_Final(unsigned char [32], SHA256_CTX *); +void HMAC_SHA256_Init(HMAC_SHA256_CTX *, const void *, size_t); +void HMAC_SHA256_Update(HMAC_SHA256_CTX *, const void *, size_t); +void HMAC_SHA256_Final(unsigned char [32], HMAC_SHA256_CTX *); + +/** + * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): + * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and + * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). + */ +void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, + uint64_t, uint8_t *, size_t); + +#endif /* !_SHA256_H_ */ diff --git a/outside/scrypt/sysendian.h b/outside/scrypt/sysendian.h new file mode 100644 index 000000000..207fb0693 --- /dev/null +++ b/outside/scrypt/sysendian.h @@ -0,0 +1,129 @@ +/*- + * Copyright 2007-2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ +#ifndef _SYSENDIAN_H_ +#define _SYSENDIAN_H_ + +#if defined(U3_OS_bsd) +#include +#else +#include + +static inline uint32_t +be32dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + + ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); +} + +static inline void +be32enc(void *pp, uint32_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[3] = x & 0xff; + p[2] = (x >> 8) & 0xff; + p[1] = (x >> 16) & 0xff; + p[0] = (x >> 24) & 0xff; +} + +static inline uint64_t +be64dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) + + ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) + + ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) + + ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56)); +} + +static inline void +be64enc(void *pp, uint64_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[7] = x & 0xff; + p[6] = (x >> 8) & 0xff; + p[5] = (x >> 16) & 0xff; + p[4] = (x >> 24) & 0xff; + p[3] = (x >> 32) & 0xff; + p[2] = (x >> 40) & 0xff; + p[1] = (x >> 48) & 0xff; + p[0] = (x >> 56) & 0xff; +} + +static inline uint32_t +le32dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + + ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); +} + +static inline void +le32enc(void *pp, uint32_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[0] = x & 0xff; + p[1] = (x >> 8) & 0xff; + p[2] = (x >> 16) & 0xff; + p[3] = (x >> 24) & 0xff; +} + +static inline uint64_t +le64dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) + + ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) + + ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) + + ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56)); +} + +static inline void +le64enc(void *pp, uint64_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[0] = x & 0xff; + p[1] = (x >> 8) & 0xff; + p[2] = (x >> 16) & 0xff; + p[3] = (x >> 24) & 0xff; + p[4] = (x >> 32) & 0xff; + p[5] = (x >> 40) & 0xff; + p[6] = (x >> 48) & 0xff; + p[7] = (x >> 56) & 0xff; +} +#endif +#endif /* !_SYSENDIAN_H_ */ From 97d679ee69a626f9837f071d37b0aef5f927152f Mon Sep 17 00:00:00 2001 From: Max G Date: Sun, 3 May 2015 15:50:28 +0300 Subject: [PATCH 18/24] fixed jet discrepancy --- Makefile | 2 +- j/e/scr.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5b94668d0..c001315d2 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ RM=rm -f CC=gcc CXX=g++ CXXFLAGS=$(CFLAGS) -CLD=g++ -L/usr/local/lib -L/opt/local/lib +CLD=g++ -g -L/usr/local/lib -L/opt/local/lib ifeq ($(OS),osx) COSFLAGS=-fno-diagnostics-fixit-info diff --git a/j/e/scr.c b/j/e/scr.c index 3d6a87978..a9cf5380d 100644 --- a/j/e/scr.c +++ b/j/e/scr.c @@ -28,7 +28,8 @@ int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, b_p[pl] = 0; b_s[sl]=0; c3_y* buf = u3a_malloc(d); - _crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d); + if (_crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d) != 0) + return u3m_bail(c3__exit); u3_noun res = u3i_bytes(d, buf); u3a_free(b_p); u3a_free(b_s); u3a_free(buf); @@ -62,7 +63,8 @@ int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, b_p[pl] = 0; b_s[sl]=0; c3_y* buf = u3a_malloc(d); - _crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d); + if (_crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d) != 0) + return u3m_bail(c3__exit); u3_noun res = u3i_bytes(d, buf); u3a_free(b_p); u3a_free(b_s); u3a_free(buf); @@ -166,6 +168,9 @@ _crypto_scrypt(const uint8_t * passwd, size_t passwdlen, uint32_t * XY; uint32_t i; + if (((N & (N-1)) != 0) || N == 0) + goto err0; + /* Sanity-check parameters. */ #if SIZE_MAX > UINT32_MAX if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { From 7443c352e13dab7cad6cb765cd47aec925c179b7 Mon Sep 17 00:00:00 2001 From: Max G Date: Sun, 3 May 2015 23:45:41 +0300 Subject: [PATCH 19/24] new bounds --- j/e/scr.c | 68 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/j/e/scr.c b/j/e/scr.c index a9cf5380d..141667af1 100644 --- a/j/e/scr.c +++ b/j/e/scr.c @@ -17,11 +17,14 @@ int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, u3qes_hsl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, u3_atom n, u3_atom r, u3_atom z, u3_atom d) { - c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && - _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && - _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && - (r * z) < 1073741824); + // asserting that n is power of 2 in _crypto_scrypt + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && + _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && + _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && + (r != 0) && (z != 0) && + (((c3_d)r * 128 * ((c3_d)n + z - 1)) <= (1 << 30)))) + return u3m_bail(c3__exit); c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); @@ -52,10 +55,13 @@ int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, u3_noun u3qes_hsh(u3_atom p, u3_atom s, u3_atom n, u3_atom r, u3_atom z, u3_atom d) { - c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && - _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && - (r * z) < 1073741824); + // asserting that n is power of 2 in _crypto_scrypt + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && + _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && + (r != 0) && (z != 0) && + (((c3_d)r * 128 * ((c3_d)n + z - 1)) <= (1 << 30)))) + return u3m_bail(c3__exit); c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); @@ -88,9 +94,12 @@ int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, u3qes_pbl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, u3_atom c, u3_atom d) { - c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && - _(u3a_is_cat(c)) && _(u3a_is_cat(d))); + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && + _(u3a_is_cat(c)) && _(u3a_is_cat(d)) && + (d <= (1 << 30)) && (c <= (1 << 28)) && + (c != 0))) + return u3m_bail(c3__exit); c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); @@ -120,8 +129,11 @@ int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, u3_noun u3qes_pbk(u3_atom p, u3_atom s, u3_atom c, u3_atom d) { - c3_assert(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(c)) && _(u3a_is_cat(d))); + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(c)) && _(u3a_is_cat(d)) && + (d <= (1 << 30)) && (c <= (1 << 28)) && + (c != 0))) + return u3m_bail(c3__exit); c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); @@ -147,6 +159,34 @@ int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, return u3qes_pbk(p, s, c, d); } +/*- + * Copyright 2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ /** * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): From 88ffabf9515e92bd638edc68f8a602337e4de078 Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Sun, 3 May 2015 16:24:09 -0700 Subject: [PATCH 20/24] Binary accidentally checked into GH. --- outside/scrypt/scrypt.a | Bin 82332 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 outside/scrypt/scrypt.a diff --git a/outside/scrypt/scrypt.a b/outside/scrypt/scrypt.a deleted file mode 100644 index 94106a866015690695216eabe99dd40198d7363f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 82332 zcmc$H30zfW`u{oiAYMcP#SKNh=*^`RxNd1`a`B=UMFmC0aY1Ae5`nnjk_sAH-i(r# z8JjGenHHy<$(p9ArUkUza!gyCwkcb+Y|$*U)&KLn=XuUOy!T$CneP90K5)y!q~jZ{NgLyCD~eTj^V?SM~)bA`G}!5Te8S9|JrPhkt32}r5II|?lXLJiXc;zu1c&@y8l=64g$_afD^UQwGz|-#>4a>}!2cYuz7J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==^Vf?!8`y?zgYahXJaFbipWUJ#ggz~LK5TJJ^f@JQ+&bZf;HMYxXfedDFT|%3-O&oVu(BO{`pAJ;p*`H#bY2|99i+!=qiKl}(= zrsL*67}0Pn?6~P`(Q(Oj-1KXp-{rXJC!sG9-i8i%IXJg3CpaB-daGLt>UPR;^PhrG zlkm+4;)Gg-*MYZ#GcG4a@dffcFTF(EJK{48pKjrqrE%O|;RWEYByJVP)qGVDx64K7 zzl+aX@JZo|4#si+h(GI@WyJ~`*LN2C)h6MrLy>UKhOZZX75O&{?*hLioKJx~7tV=m zAB5*%96K$X6W0<}Ft=WO6ksd3ecArmfbEzsdd|$Ra(WAuMm_6=p94QDybrup{5ie< zuG3pSxj25iMbG8+odjfH%z_~y4qt2=5BJsaJ z-vys_;M8A-evj~b;5EWIQUAPf&d0wDZfRMbBjKO5o1*9a#vakH#Cr8PZgu#L{9ik6 z{uiJhcHH#&W#LEIMjbc(@`wh(7spNi0Qzr^n|>PlNykk;1O2S# z;0edg|7$D@Qo@U|UK@p9!~S37xcPsE|31gfKMjArj)VCW9FBkJaC-A;0>9$8`LrYM zZO2VN0R4S%?pK^}`pD_6RKMWU@3{Hwtq4EDHYB_b{JrDeXUuW)p?(6K`EbJOPp3DZ zov8Dy|NHwteDKLgIV1Bg2+{0I1A9Dvl9;lAy9;e4>8 zSa=3}8icdXmxLdI{;BYj;GcvygU<+0rGlt!$&SA*f8T%J0nYQ@P%H~7gl|Xv(XEd5 zD|GRqC01ZL)(8Iv0}JpZxY@!wBIwpc%sB5$RI7e<40?of{5US0{nDf*7&gY`^_TYp N$$1^D7Cq1Z{{a2a0Hgo_ From ca99ef63e79f10420af58c5d27ebadabd5062e91 Mon Sep 17 00:00:00 2001 From: cgyarvin Date: Sun, 3 May 2015 16:28:51 -0700 Subject: [PATCH 21/24] Revert "Jetted scrypt" --- Makefile | 20 +- i/j/q.h | 6 - i/j/w.h | 5 - j/e/scr.c | 277 ------------------- j/tree.c | 14 - outside/scrypt/Makefile | 16 -- outside/scrypt/crypto_scrypt-sse.c | 357 ------------------------- outside/scrypt/crypto_scrypt.h | 51 ---- outside/scrypt/sha256.c | 411 ----------------------------- outside/scrypt/sha256.h | 62 ----- outside/scrypt/sysendian.h | 129 --------- 11 files changed, 6 insertions(+), 1342 deletions(-) delete mode 100644 j/e/scr.c delete mode 100644 outside/scrypt/Makefile delete mode 100644 outside/scrypt/crypto_scrypt-sse.c delete mode 100644 outside/scrypt/crypto_scrypt.h delete mode 100644 outside/scrypt/sha256.c delete mode 100644 outside/scrypt/sha256.h delete mode 100644 outside/scrypt/sysendian.h diff --git a/Makefile b/Makefile index c001315d2..c83c8a0d7 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,6 @@ CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ -Ioutside/ed25519/src \ -Ioutside/commonmark/src \ -Ioutside/commonmark/build/src \ - -Ioutside/scrypt \ $(DEFINES) \ $(MDEFINES) @@ -202,7 +201,6 @@ J_E_OFILES=\ j/e/repg.o \ j/e/rexp.o \ j/e/rub.o \ - j/e/scr.o \ j/e/shax.o \ j/e/lore.o \ j/e/loss.o \ @@ -352,8 +350,6 @@ LIBANACHRONISM=outside/anachronism/build/libanachronism.a LIBCOMMONMARK=outside/commonmark/build/src/libcmark.a -LIBSCRYPT=outside/scrypt/scrypt.a - all: vere .MAKEFILE-VERSION: Makefile .make.conf @@ -384,28 +380,25 @@ $(LIBANACHRONISM): $(LIBCOMMONMARK): $(MAKE) -C outside/commonmark -$(LIBSCRYPT): - $(MAKE) -C outside/scrypt MDEFINES="$(MDEFINES)" - $(CRE2_OFILES): outside/cre2/src/src/cre2.cpp outside/cre2/src/src/cre2.h $(LIBRE2) $(CXX) $(CXXFLAGS) -c $< -o $@ $(V_OFILES): i/v/vere.h ifdef NO_SILENT_RULES -$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) +$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) mkdir -p $(BIN) - $(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) + $(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) else -$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) +$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) @echo " CCLD $(BIN)/vere" @mkdir -p $(BIN) - @$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) + @$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) endif -$(BIN)/meme: $(LIBCRE) $(LIBCOMMONMARK) $(MEME_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) +$(BIN)/meme: $(LIBCRE) $(LIBCOMMONMARK) $(MEME_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) mkdir -p $(BIN) - $(CLD) $(CLDOSFLAGS) -o $(BIN)/meme $(MEME_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) + $(CLD) $(CLDOSFLAGS) -o $(BIN)/meme $(MEME_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) tags: ctags -R -f .tags --exclude=root @@ -440,6 +433,5 @@ distclean: clean $(LIBUV_MAKEFILE) $(MAKE) -C outside/re2 clean $(MAKE) -C outside/ed25519 clean $(MAKE) -C outside/anachronism clean - $(MAKE) -C outside/scrypt clean .PHONY: clean debbuild debinstalldistclean etags osxpackage tags diff --git a/i/j/q.h b/i/j/q.h index 04a636295..9d490f6d2 100644 --- a/i/j/q.h +++ b/i/j/q.h @@ -93,12 +93,6 @@ u3_noun u3qea_de(u3_atom, u3_atom); u3_noun u3qea_en(u3_atom, u3_atom); - u3_noun u3qes_hsh(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, u3_atom); - u3_noun u3qes_hsl(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, - u3_atom, u3_atom, u3_atom); - u3_noun u3qes_pbk(u3_atom, u3_atom, u3_atom, u3_atom); - u3_noun u3qes_pbl(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, u3_atom); - u3_noun u3qe_shax(u3_atom); u3_noun u3qe_shay(u3_atom, u3_atom); u3_noun u3qe_shas(u3_atom, u3_atom); diff --git a/i/j/w.h b/i/j/w.h index 1ebb5f286..615f237c9 100644 --- a/i/j/w.h +++ b/i/j/w.h @@ -105,11 +105,6 @@ u3_noun u3wea_de(u3_noun); u3_noun u3wea_en(u3_noun); - u3_noun u3wes_hsh(u3_noun); - u3_noun u3wes_hsl(u3_noun); - u3_noun u3wes_pbk(u3_noun); - u3_noun u3wes_pbl(u3_noun); - u3_noun u3we_shax(u3_noun); u3_noun u3we_shay(u3_noun); u3_noun u3we_shas(u3_noun); diff --git a/j/e/scr.c b/j/e/scr.c deleted file mode 100644 index 141667af1..000000000 --- a/j/e/scr.c +++ /dev/null @@ -1,277 +0,0 @@ -/* j/5/scr.c -** -*/ -#include "all.h" - -#include -#include -#include - -int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, - uint64_t, uint32_t, uint32_t, uint8_t *, size_t); - -/* functions -*/ - - u3_noun - u3qes_hsl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, u3_atom n, - u3_atom r, u3_atom z, u3_atom d) - { - // asserting that n is power of 2 in _crypto_scrypt - if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && - _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && - _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && - (r != 0) && (z != 0) && - (((c3_d)r * 128 * ((c3_d)n + z - 1)) <= (1 << 30)))) - return u3m_bail(c3__exit); - - c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); - u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); - b_p[pl] = 0; b_s[sl]=0; - c3_y* buf = u3a_malloc(d); - - if (_crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d) != 0) - return u3m_bail(c3__exit); - - u3_noun res = u3i_bytes(d, buf); - u3a_free(b_p); u3a_free(b_s); u3a_free(buf); - - return res; - } - - u3_noun - u3wes_hsl(u3_noun cor) - { - u3_noun p, pl, s, sl, n, r, z, d; - u3_noun q; - - u3x_quil(u3r_at(u3x_sam, cor), &p, &pl, &s, &sl, &q); - u3x_qual(q, &n, &r, &z, &d); - - return u3qes_hsl(p, pl, s, sl, n, r, z, d); - } - - u3_noun - u3qes_hsh(u3_atom p, u3_atom s, u3_atom n, u3_atom r, u3_atom z, u3_atom d) - { - // asserting that n is power of 2 in _crypto_scrypt - if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && - _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && - (r != 0) && (z != 0) && - (((c3_d)r * 128 * ((c3_d)n + z - 1)) <= (1 << 30)))) - return u3m_bail(c3__exit); - - c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); - c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); - u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); - b_p[pl] = 0; b_s[sl]=0; - c3_y* buf = u3a_malloc(d); - - if (_crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d) != 0) - return u3m_bail(c3__exit); - - u3_noun res = u3i_bytes(d, buf); - u3a_free(b_p); u3a_free(b_s); u3a_free(buf); - - return res; - } - - u3_noun - u3wes_hsh(u3_noun cor) - { - u3_noun p, s, n, r, z, d; - u3_noun q; - - u3x_quil(u3r_at(u3x_sam, cor), &p, &s, &n, &r, &q); - u3x_cell(q, &z, &d); - - return u3qes_hsh(p, s, n, r, z, d); - } - - u3_noun - u3qes_pbl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, - u3_atom c, u3_atom d) - { - if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && - _(u3a_is_cat(c)) && _(u3a_is_cat(d)) && - (d <= (1 << 30)) && (c <= (1 << 28)) && - (c != 0))) - return u3m_bail(c3__exit); - - c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); - u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); - b_p[pl] = 0; b_s[sl]=0; - c3_y* buf = u3a_malloc(d); - - PBKDF2_SHA256(b_p, pl, b_s, sl, c, buf, d); - - u3_noun res = u3i_bytes(d, buf); - u3a_free(b_p); u3a_free(b_s); u3a_free(buf); - - return res; - } - - u3_noun - u3wes_pbl(u3_noun cor) - { - u3_noun p, pl, s, sl, c, d; - u3_noun q; - - u3x_quil(u3r_at(u3x_sam, cor), &p, &pl, &s, &sl, &q); - u3x_cell(q, &c, &d); - - return u3qes_pbl(p, pl, s, sl, c, d); - } - - u3_noun - u3qes_pbk(u3_atom p, u3_atom s, u3_atom c, u3_atom d) - { - if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && - _(u3a_is_cat(c)) && _(u3a_is_cat(d)) && - (d <= (1 << 30)) && (c <= (1 << 28)) && - (c != 0))) - return u3m_bail(c3__exit); - - c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); - c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); - u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); - b_p[pl] = 0; b_s[sl]=0; - c3_y* buf = u3a_malloc(d); - - PBKDF2_SHA256(b_p, pl, b_s, sl, c, buf, d); - - u3_noun res = u3i_bytes(d, buf); - u3a_free(b_p); u3a_free(b_s); u3a_free(buf); - - return res; - } - - u3_noun - u3wes_pbk(u3_noun cor) - { - u3_noun p, s, c, d; - - u3x_qual(u3r_at(u3x_sam, cor), &p, &s, &c, &d); - - return u3qes_pbk(p, s, c, d); - } - -/*- - * Copyright 2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file was originally written by Colin Percival as part of the Tarsnap - * online backup system. - */ - -/** - * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): - * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, - * p, buflen) and write the result into buf. The parameters r, p, and buflen - * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N - * must be a power of 2 greater than 1. - * - * Return 0 on success; or -1 on error. - */ -int -_crypto_scrypt(const uint8_t * passwd, size_t passwdlen, - const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, - uint8_t * buf, size_t buflen) -{ - void * B0, * V0, * XY0; - uint8_t * B; - uint32_t * V; - uint32_t * XY; - uint32_t i; - - if (((N & (N-1)) != 0) || N == 0) - goto err0; - - /* Sanity-check parameters. */ -#if SIZE_MAX > UINT32_MAX - if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { - errno = EFBIG; - goto err0; - } -#endif - if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { - errno = EFBIG; - goto err0; - } - if (((N & (N - 1)) != 0) || (N == 0)) { - errno = EINVAL; - goto err0; - } - if ((r > SIZE_MAX / 128 / p) || -#if SIZE_MAX / 256 <= UINT32_MAX - (r > (SIZE_MAX - 64) / 256) || -#endif - (N > SIZE_MAX / 128 / r)) { - errno = ENOMEM; - goto err0; - } - - /* Allocate memory. */ - if ((B0 = u3a_malloc(128 * r * p + 63)) == NULL) - goto err0; - B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63)); - if ((XY0 = u3a_malloc(256 * r + 64 + 63)) == NULL) - goto err1; - XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63)); - if ((V0 = u3a_malloc(128 * r * N + 63)) == NULL) - goto err2; - V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63)); - - /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */ - PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r); - - /* 2: for i = 0 to p - 1 do */ - for (i = 0; i < p; i++) { - /* 3: B_i <-- MF(B_i, N) */ - smix(&B[i * 128 * r], r, N, V, XY); - } - - /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */ - PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen); - - /* Free memory. */ - - u3a_free(V0); - u3a_free(XY0); - u3a_free(B0); - - /* Success! */ - return (0); - -err2: - u3a_free(XY0); -err1: - u3a_free(B0); -err0: - /* Failure! */ - return (-1); -} diff --git a/j/tree.c b/j/tree.c index 6c0ff2b46..ae778d98c 100644 --- a/j/tree.c +++ b/j/tree.c @@ -231,18 +231,6 @@ static u3j_core _mood__hoon__coed_d[] = {} }; -static u3j_harm _mood__hoon__scr_hsh_a[] = {{".2", u3wes_hsh}, {}}; -static u3j_harm _mood__hoon__scr_hsl_a[] = {{".2", u3wes_hsl}, {}}; -static u3j_harm _mood__hoon__scr_pbk_a[] = {{".2", u3wes_pbk}, {}}; -static u3j_harm _mood__hoon__scr_pbl_a[] = {{".2", u3wes_pbl}, {}}; -static u3j_core _mood__hoon__scr_d[] = - { { "hsh", _mood__hoon__scr_hsh_a }, - { "hsl", _mood__hoon__scr_hsl_a }, - { "pbk", _mood__hoon__scr_pbk_a }, - { "pbl", _mood__hoon__scr_pbl_a }, - {} - }; - static u3j_harm _mood__hoon_pfix_a[] = {{".2", u3we_pfix}, {}}; static u3j_harm _mood__hoon_plug_a[] = {{".2", u3we_plug}, {}}; static u3j_harm _mood__hoon_pose_a[] = {{".2", u3we_pose}, {}}; @@ -461,8 +449,6 @@ static u3j_core _mood__hoon_d[] = { "rd", 0, _mood__hoon__rd_d }, { "coed", 0, _mood__hoon__coed_d }, - { "scr", 0, _mood__hoon__scr_d }, - { "pfix", _mood__hoon_pfix_a }, { "plug", _mood__hoon_plug_a }, { "pose", _mood__hoon_pose_a }, diff --git a/outside/scrypt/Makefile b/outside/scrypt/Makefile deleted file mode 100644 index f3ac5acb9..000000000 --- a/outside/scrypt/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -default: all - -CC?=gcc -CFLAGS?=-O2 -msse3 -ffast-math \ - -Wall -g -D_FORTIFY_SOURCE=2 -fPIC -CFLAGS_EXTRA?=-Wl,-rpath=. - -all: scrypt.a - -OBJS= crypto_scrypt-sse.o sha256.o - -scrypt.a: $(OBJS) - ar rcs scrypt.a $(OBJS) - -clean: - rm -f *.o scrypt.a diff --git a/outside/scrypt/crypto_scrypt-sse.c b/outside/scrypt/crypto_scrypt-sse.c deleted file mode 100644 index d7b33c078..000000000 --- a/outside/scrypt/crypto_scrypt-sse.c +++ /dev/null @@ -1,357 +0,0 @@ -/*- - * Copyright 2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file was originally written by Colin Percival as part of the Tarsnap - * online backup system. - */ -#include -#include - -#include -#include -#include -#include -#include - -#include "sha256.h" -#include "sysendian.h" - -#include "crypto_scrypt.h" - -static void -blkcpy(void * dest, void * src, size_t len) -{ - __m128i * D = dest; - __m128i * S = src; - size_t L = len / 16; - size_t i; - - for (i = 0; i < L; i++) - D[i] = S[i]; -} - -static void -blkxor(void * dest, void * src, size_t len) -{ - __m128i * D = dest; - __m128i * S = src; - size_t L = len / 16; - size_t i; - - for (i = 0; i < L; i++) - D[i] = _mm_xor_si128(D[i], S[i]); -} - -/** - * salsa20_8(B): - * Apply the salsa20/8 core to the provided block. - */ -static void -salsa20_8(__m128i B[4]) -{ - __m128i X0, X1, X2, X3; - __m128i T; - size_t i; - - X0 = B[0]; - X1 = B[1]; - X2 = B[2]; - X3 = B[3]; - - for (i = 0; i < 8; i += 2) { - /* Operate on "columns". */ - T = _mm_add_epi32(X0, X3); - X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 7)); - X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 25)); - T = _mm_add_epi32(X1, X0); - X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9)); - X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23)); - T = _mm_add_epi32(X2, X1); - X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 13)); - X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 19)); - T = _mm_add_epi32(X3, X2); - X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18)); - X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14)); - - /* Rearrange data. */ - X1 = _mm_shuffle_epi32(X1, 0x93); - X2 = _mm_shuffle_epi32(X2, 0x4E); - X3 = _mm_shuffle_epi32(X3, 0x39); - - /* Operate on "rows". */ - T = _mm_add_epi32(X0, X1); - X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 7)); - X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 25)); - T = _mm_add_epi32(X3, X0); - X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9)); - X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23)); - T = _mm_add_epi32(X2, X3); - X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 13)); - X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 19)); - T = _mm_add_epi32(X1, X2); - X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18)); - X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14)); - - /* Rearrange data. */ - X1 = _mm_shuffle_epi32(X1, 0x39); - X2 = _mm_shuffle_epi32(X2, 0x4E); - X3 = _mm_shuffle_epi32(X3, 0x93); - } - - B[0] = _mm_add_epi32(B[0], X0); - B[1] = _mm_add_epi32(B[1], X1); - B[2] = _mm_add_epi32(B[2], X2); - B[3] = _mm_add_epi32(B[3], X3); -} - -/** - * blockmix_salsa8(Bin, Bout, X, r): - * Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r - * bytes in length; the output Bout must also be the same size. The - * temporary space X must be 64 bytes. - */ -static void -blockmix_salsa8(__m128i * Bin, __m128i * Bout, __m128i * X, size_t r) -{ - size_t i; - - /* 1: X <-- B_{2r - 1} */ - blkcpy(X, &Bin[8 * r - 4], 64); - - /* 2: for i = 0 to 2r - 1 do */ - for (i = 0; i < r; i++) { - /* 3: X <-- H(X \xor B_i) */ - blkxor(X, &Bin[i * 8], 64); - salsa20_8(X); - - /* 4: Y_i <-- X */ - /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ - blkcpy(&Bout[i * 4], X, 64); - - /* 3: X <-- H(X \xor B_i) */ - blkxor(X, &Bin[i * 8 + 4], 64); - salsa20_8(X); - - /* 4: Y_i <-- X */ - /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ - blkcpy(&Bout[(r + i) * 4], X, 64); - } -} - -/** - * integerify(B, r): - * Return the result of parsing B_{2r-1} as a little-endian integer. - */ -static uint64_t -integerify(void * B, size_t r) -{ - uint32_t * X = (void *)((uintptr_t)(B) + (2 * r - 1) * 64); - - return (((uint64_t)(X[13]) << 32) + X[0]); -} - -/** - * smix(B, r, N, V, XY): - * Compute B = SMix_r(B, N). The input B must be 128r bytes in length; - * the temporary storage V must be 128rN bytes in length; the temporary - * storage XY must be 256r + 64 bytes in length. The value N must be a - * power of 2 greater than 1. The arrays B, V, and XY must be aligned to a - * multiple of 64 bytes. - */ -void -smix(uint8_t * B, size_t r, uint64_t N, void * V, void * XY) -{ - __m128i * X = XY; - __m128i * Y = (void *)((uintptr_t)(XY) + 128 * r); - __m128i * Z = (void *)((uintptr_t)(XY) + 256 * r); - uint32_t * X32 = (void *)X; - uint64_t i, j; - size_t k; - - /* 1: X <-- B */ - for (k = 0; k < 2 * r; k++) { - for (i = 0; i < 16; i++) { - X32[k * 16 + i] = - le32dec(&B[(k * 16 + (i * 5 % 16)) * 4]); - } - } - - /* 2: for i = 0 to N - 1 do */ - for (i = 0; i < N; i += 2) { - /* 3: V_i <-- X */ - blkcpy((void *)((uintptr_t)(V) + i * 128 * r), X, 128 * r); - - /* 4: X <-- H(X) */ - blockmix_salsa8(X, Y, Z, r); - - /* 3: V_i <-- X */ - blkcpy((void *)((uintptr_t)(V) + (i + 1) * 128 * r), - Y, 128 * r); - - /* 4: X <-- H(X) */ - blockmix_salsa8(Y, X, Z, r); - } - - /* 6: for i = 0 to N - 1 do */ - for (i = 0; i < N; i += 2) { - /* 7: j <-- Integerify(X) mod N */ - j = integerify(X, r) & (N - 1); - - /* 8: X <-- H(X \xor V_j) */ - blkxor(X, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r); - blockmix_salsa8(X, Y, Z, r); - - /* 7: j <-- Integerify(X) mod N */ - j = integerify(Y, r) & (N - 1); - - /* 8: X <-- H(X \xor V_j) */ - blkxor(Y, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r); - blockmix_salsa8(Y, X, Z, r); - } - - /* 10: B' <-- X */ - for (k = 0; k < 2 * r; k++) { - for (i = 0; i < 16; i++) { - le32enc(&B[(k * 16 + (i * 5 % 16)) * 4], - X32[k * 16 + i]); - } - } -} - -/** - * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): - * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, - * p, buflen) and write the result into buf. The parameters r, p, and buflen - * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N - * must be a power of 2 greater than 1. - * - * Return 0 on success; or -1 on error. - */ -int -crypto_scrypt(const uint8_t * passwd, size_t passwdlen, - const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, - uint8_t * buf, size_t buflen) -{ - void * B0, * V0, * XY0; - uint8_t * B; - uint32_t * V; - uint32_t * XY; - uint32_t i; - - /* Sanity-check parameters. */ -#if SIZE_MAX > UINT32_MAX - if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { - errno = EFBIG; - goto err0; - } -#endif - if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { - errno = EFBIG; - goto err0; - } - if (((N & (N - 1)) != 0) || (N == 0)) { - errno = EINVAL; - goto err0; - } - if ((r > SIZE_MAX / 128 / p) || -#if SIZE_MAX / 256 <= UINT32_MAX - (r > (SIZE_MAX - 64) / 256) || -#endif - (N > SIZE_MAX / 128 / r)) { - errno = ENOMEM; - goto err0; - } - - /* Allocate memory. */ -#ifdef HAVE_POSIX_MEMALIGN - if ((errno = posix_memalign(&B0, 64, 128 * r * p)) != 0) - goto err0; - B = (uint8_t *)(B0); - if ((errno = posix_memalign(&XY0, 64, 256 * r + 64)) != 0) - goto err1; - XY = (uint32_t *)(XY0); -#ifndef MAP_ANON - if ((errno = posix_memalign(&V0, 64, 128 * r * N)) != 0) - goto err2; - V = (uint32_t *)(V0); -#endif -#else - if ((B0 = malloc(128 * r * p + 63)) == NULL) - goto err0; - B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63)); - if ((XY0 = malloc(256 * r + 64 + 63)) == NULL) - goto err1; - XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63)); -#ifndef MAP_ANON - if ((V0 = malloc(128 * r * N + 63)) == NULL) - goto err2; - V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63)); -#endif -#endif -#ifdef MAP_ANON - if ((V0 = mmap(NULL, 128 * r * N, PROT_READ | PROT_WRITE, -#ifdef MAP_NOCORE - MAP_ANON | MAP_PRIVATE | MAP_NOCORE, -#else - MAP_ANON | MAP_PRIVATE, -#endif - -1, 0)) == MAP_FAILED) - goto err2; - V = (uint32_t *)(V0); -#endif - - /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */ - PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r); - - /* 2: for i = 0 to p - 1 do */ - for (i = 0; i < p; i++) { - /* 3: B_i <-- MF(B_i, N) */ - smix(&B[i * 128 * r], r, N, V, XY); - } - - /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */ - PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen); - - /* Free memory. */ -#ifdef MAP_ANON - if (munmap(V0, 128 * r * N)) - goto err2; -#else - free(V0); -#endif - free(XY0); - free(B0); - - /* Success! */ - return (0); - -err2: - free(XY0); -err1: - free(B0); -err0: - /* Failure! */ - return (-1); -} diff --git a/outside/scrypt/crypto_scrypt.h b/outside/scrypt/crypto_scrypt.h deleted file mode 100644 index b88be09d8..000000000 --- a/outside/scrypt/crypto_scrypt.h +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * Copyright 2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file was originally written by Colin Percival as part of the Tarsnap - * online backup system. - */ -#ifndef _CRYPTO_SCRYPT_H_ -#define _CRYPTO_SCRYPT_H_ - -#include -#include - -void smix(uint8_t *, size_t, uint64_t, void *, void *); -void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, - uint64_t, uint8_t *, size_t); - -/** - * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): - * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, - * p, buflen) and write the result into buf. The parameters r, p, and buflen - * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N - * must be a power of 2 greater than 1. - * - * Return 0 on success; or -1 on error. - */ -int crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t, - uint32_t, uint32_t, uint8_t *, size_t); - -#endif /* !_CRYPTO_SCRYPT_H_ */ diff --git a/outside/scrypt/sha256.c b/outside/scrypt/sha256.c deleted file mode 100644 index d2f915f1a..000000000 --- a/outside/scrypt/sha256.c +++ /dev/null @@ -1,411 +0,0 @@ -/*- - * Copyright 2005,2007,2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -#include -#include - -#include "sysendian.h" - -#include "sha256.h" - -/* - * Encode a length len/4 vector of (uint32_t) into a length len vector of - * (unsigned char) in big-endian form. Assumes len is a multiple of 4. - */ -static void -be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len) -{ - size_t i; - - for (i = 0; i < len / 4; i++) - be32enc(dst + i * 4, src[i]); -} - -/* - * Decode a big-endian length len vector of (unsigned char) into a length - * len/4 vector of (uint32_t). Assumes len is a multiple of 4. - */ -static void -be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len) -{ - size_t i; - - for (i = 0; i < len / 4; i++) - dst[i] = be32dec(src + i * 4); -} - -/* Elementary functions used by SHA256 */ -#define Ch(x, y, z) ((x & (y ^ z)) ^ z) -#define Maj(x, y, z) ((x & (y | z)) | (y & z)) -#define SHR(x, n) (x >> n) -#define ROTR(x, n) ((x >> n) | (x << (32 - n))) -#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) -#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) -#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) -#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) - -/* SHA256 round function */ -#define RND(a, b, c, d, e, f, g, h, k) \ - t0 = h + S1(e) + Ch(e, f, g) + k; \ - t1 = S0(a) + Maj(a, b, c); \ - d += t0; \ - h = t0 + t1; - -/* Adjusted round function for rotating state */ -#define RNDr(S, W, i, k) \ - RND(S[(64 - i) % 8], S[(65 - i) % 8], \ - S[(66 - i) % 8], S[(67 - i) % 8], \ - S[(68 - i) % 8], S[(69 - i) % 8], \ - S[(70 - i) % 8], S[(71 - i) % 8], \ - W[i] + k) - -/* - * SHA256 block compression function. The 256-bit state is transformed via - * the 512-bit input block to produce a new state. - */ -static void -SHA256_Transform(uint32_t * state, const unsigned char block[64]) -{ - uint32_t W[64]; - uint32_t S[8]; - uint32_t t0, t1; - int i; - - /* 1. Prepare message schedule W. */ - be32dec_vect(W, block, 64); - for (i = 16; i < 64; i++) - W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; - - /* 2. Initialize working variables. */ - memcpy(S, state, 32); - - /* 3. Mix. */ - RNDr(S, W, 0, 0x428a2f98); - RNDr(S, W, 1, 0x71374491); - RNDr(S, W, 2, 0xb5c0fbcf); - RNDr(S, W, 3, 0xe9b5dba5); - RNDr(S, W, 4, 0x3956c25b); - RNDr(S, W, 5, 0x59f111f1); - RNDr(S, W, 6, 0x923f82a4); - RNDr(S, W, 7, 0xab1c5ed5); - RNDr(S, W, 8, 0xd807aa98); - RNDr(S, W, 9, 0x12835b01); - RNDr(S, W, 10, 0x243185be); - RNDr(S, W, 11, 0x550c7dc3); - RNDr(S, W, 12, 0x72be5d74); - RNDr(S, W, 13, 0x80deb1fe); - RNDr(S, W, 14, 0x9bdc06a7); - RNDr(S, W, 15, 0xc19bf174); - RNDr(S, W, 16, 0xe49b69c1); - RNDr(S, W, 17, 0xefbe4786); - RNDr(S, W, 18, 0x0fc19dc6); - RNDr(S, W, 19, 0x240ca1cc); - RNDr(S, W, 20, 0x2de92c6f); - RNDr(S, W, 21, 0x4a7484aa); - RNDr(S, W, 22, 0x5cb0a9dc); - RNDr(S, W, 23, 0x76f988da); - RNDr(S, W, 24, 0x983e5152); - RNDr(S, W, 25, 0xa831c66d); - RNDr(S, W, 26, 0xb00327c8); - RNDr(S, W, 27, 0xbf597fc7); - RNDr(S, W, 28, 0xc6e00bf3); - RNDr(S, W, 29, 0xd5a79147); - RNDr(S, W, 30, 0x06ca6351); - RNDr(S, W, 31, 0x14292967); - RNDr(S, W, 32, 0x27b70a85); - RNDr(S, W, 33, 0x2e1b2138); - RNDr(S, W, 34, 0x4d2c6dfc); - RNDr(S, W, 35, 0x53380d13); - RNDr(S, W, 36, 0x650a7354); - RNDr(S, W, 37, 0x766a0abb); - RNDr(S, W, 38, 0x81c2c92e); - RNDr(S, W, 39, 0x92722c85); - RNDr(S, W, 40, 0xa2bfe8a1); - RNDr(S, W, 41, 0xa81a664b); - RNDr(S, W, 42, 0xc24b8b70); - RNDr(S, W, 43, 0xc76c51a3); - RNDr(S, W, 44, 0xd192e819); - RNDr(S, W, 45, 0xd6990624); - RNDr(S, W, 46, 0xf40e3585); - RNDr(S, W, 47, 0x106aa070); - RNDr(S, W, 48, 0x19a4c116); - RNDr(S, W, 49, 0x1e376c08); - RNDr(S, W, 50, 0x2748774c); - RNDr(S, W, 51, 0x34b0bcb5); - RNDr(S, W, 52, 0x391c0cb3); - RNDr(S, W, 53, 0x4ed8aa4a); - RNDr(S, W, 54, 0x5b9cca4f); - RNDr(S, W, 55, 0x682e6ff3); - RNDr(S, W, 56, 0x748f82ee); - RNDr(S, W, 57, 0x78a5636f); - RNDr(S, W, 58, 0x84c87814); - RNDr(S, W, 59, 0x8cc70208); - RNDr(S, W, 60, 0x90befffa); - RNDr(S, W, 61, 0xa4506ceb); - RNDr(S, W, 62, 0xbef9a3f7); - RNDr(S, W, 63, 0xc67178f2); - - /* 4. Mix local working variables into global state */ - for (i = 0; i < 8; i++) - state[i] += S[i]; - - /* Clean the stack. */ - memset(W, 0, 256); - memset(S, 0, 32); - t0 = t1 = 0; -} - -static unsigned char PAD[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* Add padding and terminating bit-count. */ -static void -SHA256_Pad(SHA256_CTX * ctx) -{ - unsigned char len[8]; - uint32_t r, plen; - - /* - * Convert length to a vector of bytes -- we do this now rather - * than later because the length will change after we pad. - */ - be32enc_vect(len, ctx->count, 8); - - /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ - r = (ctx->count[1] >> 3) & 0x3f; - plen = (r < 56) ? (56 - r) : (120 - r); - SHA256_Update(ctx, PAD, (size_t)plen); - - /* Add the terminating bit-count */ - SHA256_Update(ctx, len, 8); -} - -/* SHA-256 initialization. Begins a SHA-256 operation. */ -void -SHA256_Init(SHA256_CTX * ctx) -{ - - /* Zero bits processed so far */ - ctx->count[0] = ctx->count[1] = 0; - - /* Magic initialization constants */ - ctx->state[0] = 0x6A09E667; - ctx->state[1] = 0xBB67AE85; - ctx->state[2] = 0x3C6EF372; - ctx->state[3] = 0xA54FF53A; - ctx->state[4] = 0x510E527F; - ctx->state[5] = 0x9B05688C; - ctx->state[6] = 0x1F83D9AB; - ctx->state[7] = 0x5BE0CD19; -} - -/* Add bytes into the hash */ -void -SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) -{ - uint32_t bitlen[2]; - uint32_t r; - const unsigned char *src = in; - - /* Number of bytes left in the buffer from previous updates */ - r = (ctx->count[1] >> 3) & 0x3f; - - /* Convert the length into a number of bits */ - bitlen[1] = ((uint32_t)len) << 3; - bitlen[0] = (uint32_t)(len >> 29); - - /* Update number of bits */ - if ((ctx->count[1] += bitlen[1]) < bitlen[1]) - ctx->count[0]++; - ctx->count[0] += bitlen[0]; - - /* Handle the case where we don't need to perform any transforms */ - if (len < 64 - r) { - memcpy(&ctx->buf[r], src, len); - return; - } - - /* Finish the current block */ - memcpy(&ctx->buf[r], src, 64 - r); - SHA256_Transform(ctx->state, ctx->buf); - src += 64 - r; - len -= 64 - r; - - /* Perform complete blocks */ - while (len >= 64) { - SHA256_Transform(ctx->state, src); - src += 64; - len -= 64; - } - - /* Copy left over data into buffer */ - memcpy(ctx->buf, src, len); -} - -/* - * SHA-256 finalization. Pads the input data, exports the hash value, - * and clears the context state. - */ -void -SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx) -{ - - /* Add padding */ - SHA256_Pad(ctx); - - /* Write the hash */ - be32enc_vect(digest, ctx->state, 32); - - /* Clear the context state */ - memset((void *)ctx, 0, sizeof(*ctx)); -} - -/* Initialize an HMAC-SHA256 operation with the given key. */ -void -HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen) -{ - unsigned char pad[64]; - unsigned char khash[32]; - const unsigned char * K = _K; - size_t i; - - /* If Klen > 64, the key is really SHA256(K). */ - if (Klen > 64) { - SHA256_Init(&ctx->ictx); - SHA256_Update(&ctx->ictx, K, Klen); - SHA256_Final(khash, &ctx->ictx); - K = khash; - Klen = 32; - } - - /* Inner SHA256 operation is SHA256(K xor [block of 0x36] || data). */ - SHA256_Init(&ctx->ictx); - memset(pad, 0x36, 64); - for (i = 0; i < Klen; i++) - pad[i] ^= K[i]; - SHA256_Update(&ctx->ictx, pad, 64); - - /* Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash). */ - SHA256_Init(&ctx->octx); - memset(pad, 0x5c, 64); - for (i = 0; i < Klen; i++) - pad[i] ^= K[i]; - SHA256_Update(&ctx->octx, pad, 64); - - /* Clean the stack. */ - memset(khash, 0, 32); -} - -/* Add bytes to the HMAC-SHA256 operation. */ -void -HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void *in, size_t len) -{ - - /* Feed data to the inner SHA256 operation. */ - SHA256_Update(&ctx->ictx, in, len); -} - -/* Finish an HMAC-SHA256 operation. */ -void -HMAC_SHA256_Final(unsigned char digest[32], HMAC_SHA256_CTX * ctx) -{ - unsigned char ihash[32]; - - /* Finish the inner SHA256 operation. */ - SHA256_Final(ihash, &ctx->ictx); - - /* Feed the inner hash to the outer SHA256 operation. */ - SHA256_Update(&ctx->octx, ihash, 32); - - /* Finish the outer SHA256 operation. */ - SHA256_Final(digest, &ctx->octx); - - /* Clean the stack. */ - memset(ihash, 0, 32); -} - -/** - * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): - * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and - * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). - */ -void -PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, - size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen) -{ - HMAC_SHA256_CTX PShctx, hctx; - size_t i; - uint8_t ivec[4]; - uint8_t U[32]; - uint8_t T[32]; - uint64_t j; - int k; - size_t clen; - - /* Compute HMAC state after processing P and S. */ - HMAC_SHA256_Init(&PShctx, passwd, passwdlen); - HMAC_SHA256_Update(&PShctx, salt, saltlen); - - /* Iterate through the blocks. */ - for (i = 0; i * 32 < dkLen; i++) { - /* Generate INT(i + 1). */ - be32enc(ivec, (uint32_t)(i + 1)); - - /* Compute U_1 = PRF(P, S || INT(i)). */ - memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX)); - HMAC_SHA256_Update(&hctx, ivec, 4); - HMAC_SHA256_Final(U, &hctx); - - /* T_i = U_1 ... */ - memcpy(T, U, 32); - - for (j = 2; j <= c; j++) { - /* Compute U_j. */ - HMAC_SHA256_Init(&hctx, passwd, passwdlen); - HMAC_SHA256_Update(&hctx, U, 32); - HMAC_SHA256_Final(U, &hctx); - - /* ... xor U_j ... */ - for (k = 0; k < 32; k++) - T[k] ^= U[k]; - } - - /* Copy as many bytes as necessary into buf. */ - clen = dkLen - i * 32; - if (clen > 32) - clen = 32; - memcpy(&buf[i * 32], T, clen); - } - - /* Clean PShctx, since we never called _Final on it. */ - memset(&PShctx, 0, sizeof(HMAC_SHA256_CTX)); -} diff --git a/outside/scrypt/sha256.h b/outside/scrypt/sha256.h deleted file mode 100644 index 289a5232f..000000000 --- a/outside/scrypt/sha256.h +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright 2005,2007,2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD: src/lib/libmd/sha256.h,v 1.2 2006/01/17 15:35:56 phk Exp $ - */ - -#ifndef _SHA256_H_ -#define _SHA256_H_ - -#include - -#include - -typedef struct SHA256Context { - uint32_t state[8]; - uint32_t count[2]; - unsigned char buf[64]; -} SHA256_CTX; - -typedef struct HMAC_SHA256Context { - SHA256_CTX ictx; - SHA256_CTX octx; -} HMAC_SHA256_CTX; - -void SHA256_Init(SHA256_CTX *); -void SHA256_Update(SHA256_CTX *, const void *, size_t); -void SHA256_Final(unsigned char [32], SHA256_CTX *); -void HMAC_SHA256_Init(HMAC_SHA256_CTX *, const void *, size_t); -void HMAC_SHA256_Update(HMAC_SHA256_CTX *, const void *, size_t); -void HMAC_SHA256_Final(unsigned char [32], HMAC_SHA256_CTX *); - -/** - * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): - * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and - * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). - */ -void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, - uint64_t, uint8_t *, size_t); - -#endif /* !_SHA256_H_ */ diff --git a/outside/scrypt/sysendian.h b/outside/scrypt/sysendian.h deleted file mode 100644 index 207fb0693..000000000 --- a/outside/scrypt/sysendian.h +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * Copyright 2007-2009 Colin Percival - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file was originally written by Colin Percival as part of the Tarsnap - * online backup system. - */ -#ifndef _SYSENDIAN_H_ -#define _SYSENDIAN_H_ - -#if defined(U3_OS_bsd) -#include -#else -#include - -static inline uint32_t -be32dec(const void *pp) -{ - const uint8_t *p = (uint8_t const *)pp; - - return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + - ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); -} - -static inline void -be32enc(void *pp, uint32_t x) -{ - uint8_t * p = (uint8_t *)pp; - - p[3] = x & 0xff; - p[2] = (x >> 8) & 0xff; - p[1] = (x >> 16) & 0xff; - p[0] = (x >> 24) & 0xff; -} - -static inline uint64_t -be64dec(const void *pp) -{ - const uint8_t *p = (uint8_t const *)pp; - - return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) + - ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) + - ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) + - ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56)); -} - -static inline void -be64enc(void *pp, uint64_t x) -{ - uint8_t * p = (uint8_t *)pp; - - p[7] = x & 0xff; - p[6] = (x >> 8) & 0xff; - p[5] = (x >> 16) & 0xff; - p[4] = (x >> 24) & 0xff; - p[3] = (x >> 32) & 0xff; - p[2] = (x >> 40) & 0xff; - p[1] = (x >> 48) & 0xff; - p[0] = (x >> 56) & 0xff; -} - -static inline uint32_t -le32dec(const void *pp) -{ - const uint8_t *p = (uint8_t const *)pp; - - return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + - ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); -} - -static inline void -le32enc(void *pp, uint32_t x) -{ - uint8_t * p = (uint8_t *)pp; - - p[0] = x & 0xff; - p[1] = (x >> 8) & 0xff; - p[2] = (x >> 16) & 0xff; - p[3] = (x >> 24) & 0xff; -} - -static inline uint64_t -le64dec(const void *pp) -{ - const uint8_t *p = (uint8_t const *)pp; - - return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) + - ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) + - ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) + - ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56)); -} - -static inline void -le64enc(void *pp, uint64_t x) -{ - uint8_t * p = (uint8_t *)pp; - - p[0] = x & 0xff; - p[1] = (x >> 8) & 0xff; - p[2] = (x >> 16) & 0xff; - p[3] = (x >> 24) & 0xff; - p[4] = (x >> 32) & 0xff; - p[5] = (x >> 40) & 0xff; - p[6] = (x >> 48) & 0xff; - p[7] = (x >> 56) & 0xff; -} -#endif -#endif /* !_SYSENDIAN_H_ */ From b812d16b0aff755289ff7399e7ecbf94fc4eb8cd Mon Sep 17 00:00:00 2001 From: cgyarvin Date: Sun, 3 May 2015 16:31:45 -0700 Subject: [PATCH 22/24] Revert "Revert "Jetted scrypt"" --- Makefile | 20 +- i/j/q.h | 6 + i/j/w.h | 5 + j/e/scr.c | 277 +++++++++++++++++++ j/tree.c | 14 + outside/scrypt/Makefile | 16 ++ outside/scrypt/crypto_scrypt-sse.c | 357 +++++++++++++++++++++++++ outside/scrypt/crypto_scrypt.h | 51 ++++ outside/scrypt/sha256.c | 411 +++++++++++++++++++++++++++++ outside/scrypt/sha256.h | 62 +++++ outside/scrypt/sysendian.h | 129 +++++++++ 11 files changed, 1342 insertions(+), 6 deletions(-) create mode 100644 j/e/scr.c create mode 100644 outside/scrypt/Makefile create mode 100644 outside/scrypt/crypto_scrypt-sse.c create mode 100644 outside/scrypt/crypto_scrypt.h create mode 100644 outside/scrypt/sha256.c create mode 100644 outside/scrypt/sha256.h create mode 100644 outside/scrypt/sysendian.h diff --git a/Makefile b/Makefile index c83c8a0d7..c001315d2 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,7 @@ CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ -Ioutside/ed25519/src \ -Ioutside/commonmark/src \ -Ioutside/commonmark/build/src \ + -Ioutside/scrypt \ $(DEFINES) \ $(MDEFINES) @@ -201,6 +202,7 @@ J_E_OFILES=\ j/e/repg.o \ j/e/rexp.o \ j/e/rub.o \ + j/e/scr.o \ j/e/shax.o \ j/e/lore.o \ j/e/loss.o \ @@ -350,6 +352,8 @@ LIBANACHRONISM=outside/anachronism/build/libanachronism.a LIBCOMMONMARK=outside/commonmark/build/src/libcmark.a +LIBSCRYPT=outside/scrypt/scrypt.a + all: vere .MAKEFILE-VERSION: Makefile .make.conf @@ -380,25 +384,28 @@ $(LIBANACHRONISM): $(LIBCOMMONMARK): $(MAKE) -C outside/commonmark +$(LIBSCRYPT): + $(MAKE) -C outside/scrypt MDEFINES="$(MDEFINES)" + $(CRE2_OFILES): outside/cre2/src/src/cre2.cpp outside/cre2/src/src/cre2.h $(LIBRE2) $(CXX) $(CXXFLAGS) -c $< -o $@ $(V_OFILES): i/v/vere.h ifdef NO_SILENT_RULES -$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) +$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) mkdir -p $(BIN) - $(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) + $(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) else -$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) +$(BIN)/vere: $(LIBCRE) $(LIBCOMMONMARK) $(VERE_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) @echo " CCLD $(BIN)/vere" @mkdir -p $(BIN) - @$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) + @$(CLD) $(CLDOSFLAGS) -o $(BIN)/vere $(VERE_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) endif -$(BIN)/meme: $(LIBCRE) $(LIBCOMMONMARK) $(MEME_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) +$(BIN)/meme: $(LIBCRE) $(LIBCOMMONMARK) $(MEME_OFILES) $(LIBUV) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBSCRYPT) mkdir -p $(BIN) - $(CLD) $(CLDOSFLAGS) -o $(BIN)/meme $(MEME_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) + $(CLD) $(CLDOSFLAGS) -o $(BIN)/meme $(MEME_OFILES) $(LIBUV) $(LIBCRE) $(LIBRE2) $(LIBED25519) $(LIBANACHRONISM) $(LIBS) $(LIBCOMMONMARK) $(LIBSCRYPT) tags: ctags -R -f .tags --exclude=root @@ -433,5 +440,6 @@ distclean: clean $(LIBUV_MAKEFILE) $(MAKE) -C outside/re2 clean $(MAKE) -C outside/ed25519 clean $(MAKE) -C outside/anachronism clean + $(MAKE) -C outside/scrypt clean .PHONY: clean debbuild debinstalldistclean etags osxpackage tags diff --git a/i/j/q.h b/i/j/q.h index 9d490f6d2..04a636295 100644 --- a/i/j/q.h +++ b/i/j/q.h @@ -93,6 +93,12 @@ u3_noun u3qea_de(u3_atom, u3_atom); u3_noun u3qea_en(u3_atom, u3_atom); + u3_noun u3qes_hsh(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, u3_atom); + u3_noun u3qes_hsl(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, + u3_atom, u3_atom, u3_atom); + u3_noun u3qes_pbk(u3_atom, u3_atom, u3_atom, u3_atom); + u3_noun u3qes_pbl(u3_atom, u3_atom, u3_atom, u3_atom, u3_atom, u3_atom); + u3_noun u3qe_shax(u3_atom); u3_noun u3qe_shay(u3_atom, u3_atom); u3_noun u3qe_shas(u3_atom, u3_atom); diff --git a/i/j/w.h b/i/j/w.h index 615f237c9..1ebb5f286 100644 --- a/i/j/w.h +++ b/i/j/w.h @@ -105,6 +105,11 @@ u3_noun u3wea_de(u3_noun); u3_noun u3wea_en(u3_noun); + u3_noun u3wes_hsh(u3_noun); + u3_noun u3wes_hsl(u3_noun); + u3_noun u3wes_pbk(u3_noun); + u3_noun u3wes_pbl(u3_noun); + u3_noun u3we_shax(u3_noun); u3_noun u3we_shay(u3_noun); u3_noun u3we_shas(u3_noun); diff --git a/j/e/scr.c b/j/e/scr.c new file mode 100644 index 000000000..141667af1 --- /dev/null +++ b/j/e/scr.c @@ -0,0 +1,277 @@ +/* j/5/scr.c +** +*/ +#include "all.h" + +#include +#include +#include + +int _crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, + uint64_t, uint32_t, uint32_t, uint8_t *, size_t); + +/* functions +*/ + + u3_noun + u3qes_hsl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, u3_atom n, + u3_atom r, u3_atom z, u3_atom d) + { + // asserting that n is power of 2 in _crypto_scrypt + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && + _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && + _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && + (r != 0) && (z != 0) && + (((c3_d)r * 128 * ((c3_d)n + z - 1)) <= (1 << 30)))) + return u3m_bail(c3__exit); + + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + if (_crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d) != 0) + return u3m_bail(c3__exit); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_hsl(u3_noun cor) + { + u3_noun p, pl, s, sl, n, r, z, d; + u3_noun q; + + u3x_quil(u3r_at(u3x_sam, cor), &p, &pl, &s, &sl, &q); + u3x_qual(q, &n, &r, &z, &d); + + return u3qes_hsl(p, pl, s, sl, n, r, z, d); + } + + u3_noun + u3qes_hsh(u3_atom p, u3_atom s, u3_atom n, u3_atom r, u3_atom z, u3_atom d) + { + // asserting that n is power of 2 in _crypto_scrypt + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(n)) && _(u3a_is_cat(r)) && + _(u3a_is_cat(z)) && _(u3a_is_cat(d)) && + (r != 0) && (z != 0) && + (((c3_d)r * 128 * ((c3_d)n + z - 1)) <= (1 << 30)))) + return u3m_bail(c3__exit); + + c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(sl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + if (_crypto_scrypt(b_p, pl, b_s, sl, n, r, z, buf, d) != 0) + return u3m_bail(c3__exit); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_hsh(u3_noun cor) + { + u3_noun p, s, n, r, z, d; + u3_noun q; + + u3x_quil(u3r_at(u3x_sam, cor), &p, &s, &n, &r, &q); + u3x_cell(q, &z, &d); + + return u3qes_hsh(p, s, n, r, z, d); + } + + u3_noun + u3qes_pbl(u3_atom p, u3_atom pl, u3_atom s, u3_atom sl, + u3_atom c, u3_atom d) + { + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(pl)) && _(u3a_is_cat(sl)) && + _(u3a_is_cat(c)) && _(u3a_is_cat(d)) && + (d <= (1 << 30)) && (c <= (1 << 28)) && + (c != 0))) + return u3m_bail(c3__exit); + + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + PBKDF2_SHA256(b_p, pl, b_s, sl, c, buf, d); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_pbl(u3_noun cor) + { + u3_noun p, pl, s, sl, c, d; + u3_noun q; + + u3x_quil(u3r_at(u3x_sam, cor), &p, &pl, &s, &sl, &q); + u3x_cell(q, &c, &d); + + return u3qes_pbl(p, pl, s, sl, c, d); + } + + u3_noun + u3qes_pbk(u3_atom p, u3_atom s, u3_atom c, u3_atom d) + { + if (!(_(u3a_is_atom(p)) && _(u3a_is_atom(s)) && + _(u3a_is_cat(c)) && _(u3a_is_cat(d)) && + (d <= (1 << 30)) && (c <= (1 << 28)) && + (c != 0))) + return u3m_bail(c3__exit); + + c3_w pl = u3r_met(3, p); c3_w sl = u3r_met(3, s); + c3_y* b_p = u3a_malloc(pl + 1); c3_y* b_s= u3a_malloc(pl + 1); + u3r_bytes(0, pl, b_p, p); u3r_bytes(0, sl, b_s, s); + b_p[pl] = 0; b_s[sl]=0; + c3_y* buf = u3a_malloc(d); + + PBKDF2_SHA256(b_p, pl, b_s, sl, c, buf, d); + + u3_noun res = u3i_bytes(d, buf); + u3a_free(b_p); u3a_free(b_s); u3a_free(buf); + + return res; + } + + u3_noun + u3wes_pbk(u3_noun cor) + { + u3_noun p, s, c, d; + + u3x_qual(u3r_at(u3x_sam, cor), &p, &s, &c, &d); + + return u3qes_pbk(p, s, c, d); + } + +/*- + * Copyright 2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ + +/** + * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): + * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, + * p, buflen) and write the result into buf. The parameters r, p, and buflen + * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N + * must be a power of 2 greater than 1. + * + * Return 0 on success; or -1 on error. + */ +int +_crypto_scrypt(const uint8_t * passwd, size_t passwdlen, + const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, + uint8_t * buf, size_t buflen) +{ + void * B0, * V0, * XY0; + uint8_t * B; + uint32_t * V; + uint32_t * XY; + uint32_t i; + + if (((N & (N-1)) != 0) || N == 0) + goto err0; + + /* Sanity-check parameters. */ +#if SIZE_MAX > UINT32_MAX + if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { + errno = EFBIG; + goto err0; + } +#endif + if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { + errno = EFBIG; + goto err0; + } + if (((N & (N - 1)) != 0) || (N == 0)) { + errno = EINVAL; + goto err0; + } + if ((r > SIZE_MAX / 128 / p) || +#if SIZE_MAX / 256 <= UINT32_MAX + (r > (SIZE_MAX - 64) / 256) || +#endif + (N > SIZE_MAX / 128 / r)) { + errno = ENOMEM; + goto err0; + } + + /* Allocate memory. */ + if ((B0 = u3a_malloc(128 * r * p + 63)) == NULL) + goto err0; + B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63)); + if ((XY0 = u3a_malloc(256 * r + 64 + 63)) == NULL) + goto err1; + XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63)); + if ((V0 = u3a_malloc(128 * r * N + 63)) == NULL) + goto err2; + V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63)); + + /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */ + PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r); + + /* 2: for i = 0 to p - 1 do */ + for (i = 0; i < p; i++) { + /* 3: B_i <-- MF(B_i, N) */ + smix(&B[i * 128 * r], r, N, V, XY); + } + + /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */ + PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen); + + /* Free memory. */ + + u3a_free(V0); + u3a_free(XY0); + u3a_free(B0); + + /* Success! */ + return (0); + +err2: + u3a_free(XY0); +err1: + u3a_free(B0); +err0: + /* Failure! */ + return (-1); +} diff --git a/j/tree.c b/j/tree.c index ae778d98c..6c0ff2b46 100644 --- a/j/tree.c +++ b/j/tree.c @@ -231,6 +231,18 @@ static u3j_core _mood__hoon__coed_d[] = {} }; +static u3j_harm _mood__hoon__scr_hsh_a[] = {{".2", u3wes_hsh}, {}}; +static u3j_harm _mood__hoon__scr_hsl_a[] = {{".2", u3wes_hsl}, {}}; +static u3j_harm _mood__hoon__scr_pbk_a[] = {{".2", u3wes_pbk}, {}}; +static u3j_harm _mood__hoon__scr_pbl_a[] = {{".2", u3wes_pbl}, {}}; +static u3j_core _mood__hoon__scr_d[] = + { { "hsh", _mood__hoon__scr_hsh_a }, + { "hsl", _mood__hoon__scr_hsl_a }, + { "pbk", _mood__hoon__scr_pbk_a }, + { "pbl", _mood__hoon__scr_pbl_a }, + {} + }; + static u3j_harm _mood__hoon_pfix_a[] = {{".2", u3we_pfix}, {}}; static u3j_harm _mood__hoon_plug_a[] = {{".2", u3we_plug}, {}}; static u3j_harm _mood__hoon_pose_a[] = {{".2", u3we_pose}, {}}; @@ -449,6 +461,8 @@ static u3j_core _mood__hoon_d[] = { "rd", 0, _mood__hoon__rd_d }, { "coed", 0, _mood__hoon__coed_d }, + { "scr", 0, _mood__hoon__scr_d }, + { "pfix", _mood__hoon_pfix_a }, { "plug", _mood__hoon_plug_a }, { "pose", _mood__hoon_pose_a }, diff --git a/outside/scrypt/Makefile b/outside/scrypt/Makefile new file mode 100644 index 000000000..f3ac5acb9 --- /dev/null +++ b/outside/scrypt/Makefile @@ -0,0 +1,16 @@ +default: all + +CC?=gcc +CFLAGS?=-O2 -msse3 -ffast-math \ + -Wall -g -D_FORTIFY_SOURCE=2 -fPIC +CFLAGS_EXTRA?=-Wl,-rpath=. + +all: scrypt.a + +OBJS= crypto_scrypt-sse.o sha256.o + +scrypt.a: $(OBJS) + ar rcs scrypt.a $(OBJS) + +clean: + rm -f *.o scrypt.a diff --git a/outside/scrypt/crypto_scrypt-sse.c b/outside/scrypt/crypto_scrypt-sse.c new file mode 100644 index 000000000..d7b33c078 --- /dev/null +++ b/outside/scrypt/crypto_scrypt-sse.c @@ -0,0 +1,357 @@ +/*- + * Copyright 2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ +#include +#include + +#include +#include +#include +#include +#include + +#include "sha256.h" +#include "sysendian.h" + +#include "crypto_scrypt.h" + +static void +blkcpy(void * dest, void * src, size_t len) +{ + __m128i * D = dest; + __m128i * S = src; + size_t L = len / 16; + size_t i; + + for (i = 0; i < L; i++) + D[i] = S[i]; +} + +static void +blkxor(void * dest, void * src, size_t len) +{ + __m128i * D = dest; + __m128i * S = src; + size_t L = len / 16; + size_t i; + + for (i = 0; i < L; i++) + D[i] = _mm_xor_si128(D[i], S[i]); +} + +/** + * salsa20_8(B): + * Apply the salsa20/8 core to the provided block. + */ +static void +salsa20_8(__m128i B[4]) +{ + __m128i X0, X1, X2, X3; + __m128i T; + size_t i; + + X0 = B[0]; + X1 = B[1]; + X2 = B[2]; + X3 = B[3]; + + for (i = 0; i < 8; i += 2) { + /* Operate on "columns". */ + T = _mm_add_epi32(X0, X3); + X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 7)); + X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 25)); + T = _mm_add_epi32(X1, X0); + X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9)); + X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23)); + T = _mm_add_epi32(X2, X1); + X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 13)); + X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 19)); + T = _mm_add_epi32(X3, X2); + X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18)); + X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14)); + + /* Rearrange data. */ + X1 = _mm_shuffle_epi32(X1, 0x93); + X2 = _mm_shuffle_epi32(X2, 0x4E); + X3 = _mm_shuffle_epi32(X3, 0x39); + + /* Operate on "rows". */ + T = _mm_add_epi32(X0, X1); + X3 = _mm_xor_si128(X3, _mm_slli_epi32(T, 7)); + X3 = _mm_xor_si128(X3, _mm_srli_epi32(T, 25)); + T = _mm_add_epi32(X3, X0); + X2 = _mm_xor_si128(X2, _mm_slli_epi32(T, 9)); + X2 = _mm_xor_si128(X2, _mm_srli_epi32(T, 23)); + T = _mm_add_epi32(X2, X3); + X1 = _mm_xor_si128(X1, _mm_slli_epi32(T, 13)); + X1 = _mm_xor_si128(X1, _mm_srli_epi32(T, 19)); + T = _mm_add_epi32(X1, X2); + X0 = _mm_xor_si128(X0, _mm_slli_epi32(T, 18)); + X0 = _mm_xor_si128(X0, _mm_srli_epi32(T, 14)); + + /* Rearrange data. */ + X1 = _mm_shuffle_epi32(X1, 0x39); + X2 = _mm_shuffle_epi32(X2, 0x4E); + X3 = _mm_shuffle_epi32(X3, 0x93); + } + + B[0] = _mm_add_epi32(B[0], X0); + B[1] = _mm_add_epi32(B[1], X1); + B[2] = _mm_add_epi32(B[2], X2); + B[3] = _mm_add_epi32(B[3], X3); +} + +/** + * blockmix_salsa8(Bin, Bout, X, r): + * Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r + * bytes in length; the output Bout must also be the same size. The + * temporary space X must be 64 bytes. + */ +static void +blockmix_salsa8(__m128i * Bin, __m128i * Bout, __m128i * X, size_t r) +{ + size_t i; + + /* 1: X <-- B_{2r - 1} */ + blkcpy(X, &Bin[8 * r - 4], 64); + + /* 2: for i = 0 to 2r - 1 do */ + for (i = 0; i < r; i++) { + /* 3: X <-- H(X \xor B_i) */ + blkxor(X, &Bin[i * 8], 64); + salsa20_8(X); + + /* 4: Y_i <-- X */ + /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ + blkcpy(&Bout[i * 4], X, 64); + + /* 3: X <-- H(X \xor B_i) */ + blkxor(X, &Bin[i * 8 + 4], 64); + salsa20_8(X); + + /* 4: Y_i <-- X */ + /* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */ + blkcpy(&Bout[(r + i) * 4], X, 64); + } +} + +/** + * integerify(B, r): + * Return the result of parsing B_{2r-1} as a little-endian integer. + */ +static uint64_t +integerify(void * B, size_t r) +{ + uint32_t * X = (void *)((uintptr_t)(B) + (2 * r - 1) * 64); + + return (((uint64_t)(X[13]) << 32) + X[0]); +} + +/** + * smix(B, r, N, V, XY): + * Compute B = SMix_r(B, N). The input B must be 128r bytes in length; + * the temporary storage V must be 128rN bytes in length; the temporary + * storage XY must be 256r + 64 bytes in length. The value N must be a + * power of 2 greater than 1. The arrays B, V, and XY must be aligned to a + * multiple of 64 bytes. + */ +void +smix(uint8_t * B, size_t r, uint64_t N, void * V, void * XY) +{ + __m128i * X = XY; + __m128i * Y = (void *)((uintptr_t)(XY) + 128 * r); + __m128i * Z = (void *)((uintptr_t)(XY) + 256 * r); + uint32_t * X32 = (void *)X; + uint64_t i, j; + size_t k; + + /* 1: X <-- B */ + for (k = 0; k < 2 * r; k++) { + for (i = 0; i < 16; i++) { + X32[k * 16 + i] = + le32dec(&B[(k * 16 + (i * 5 % 16)) * 4]); + } + } + + /* 2: for i = 0 to N - 1 do */ + for (i = 0; i < N; i += 2) { + /* 3: V_i <-- X */ + blkcpy((void *)((uintptr_t)(V) + i * 128 * r), X, 128 * r); + + /* 4: X <-- H(X) */ + blockmix_salsa8(X, Y, Z, r); + + /* 3: V_i <-- X */ + blkcpy((void *)((uintptr_t)(V) + (i + 1) * 128 * r), + Y, 128 * r); + + /* 4: X <-- H(X) */ + blockmix_salsa8(Y, X, Z, r); + } + + /* 6: for i = 0 to N - 1 do */ + for (i = 0; i < N; i += 2) { + /* 7: j <-- Integerify(X) mod N */ + j = integerify(X, r) & (N - 1); + + /* 8: X <-- H(X \xor V_j) */ + blkxor(X, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r); + blockmix_salsa8(X, Y, Z, r); + + /* 7: j <-- Integerify(X) mod N */ + j = integerify(Y, r) & (N - 1); + + /* 8: X <-- H(X \xor V_j) */ + blkxor(Y, (void *)((uintptr_t)(V) + j * 128 * r), 128 * r); + blockmix_salsa8(Y, X, Z, r); + } + + /* 10: B' <-- X */ + for (k = 0; k < 2 * r; k++) { + for (i = 0; i < 16; i++) { + le32enc(&B[(k * 16 + (i * 5 % 16)) * 4], + X32[k * 16 + i]); + } + } +} + +/** + * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): + * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, + * p, buflen) and write the result into buf. The parameters r, p, and buflen + * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N + * must be a power of 2 greater than 1. + * + * Return 0 on success; or -1 on error. + */ +int +crypto_scrypt(const uint8_t * passwd, size_t passwdlen, + const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, + uint8_t * buf, size_t buflen) +{ + void * B0, * V0, * XY0; + uint8_t * B; + uint32_t * V; + uint32_t * XY; + uint32_t i; + + /* Sanity-check parameters. */ +#if SIZE_MAX > UINT32_MAX + if (buflen > (((uint64_t)(1) << 32) - 1) * 32) { + errno = EFBIG; + goto err0; + } +#endif + if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) { + errno = EFBIG; + goto err0; + } + if (((N & (N - 1)) != 0) || (N == 0)) { + errno = EINVAL; + goto err0; + } + if ((r > SIZE_MAX / 128 / p) || +#if SIZE_MAX / 256 <= UINT32_MAX + (r > (SIZE_MAX - 64) / 256) || +#endif + (N > SIZE_MAX / 128 / r)) { + errno = ENOMEM; + goto err0; + } + + /* Allocate memory. */ +#ifdef HAVE_POSIX_MEMALIGN + if ((errno = posix_memalign(&B0, 64, 128 * r * p)) != 0) + goto err0; + B = (uint8_t *)(B0); + if ((errno = posix_memalign(&XY0, 64, 256 * r + 64)) != 0) + goto err1; + XY = (uint32_t *)(XY0); +#ifndef MAP_ANON + if ((errno = posix_memalign(&V0, 64, 128 * r * N)) != 0) + goto err2; + V = (uint32_t *)(V0); +#endif +#else + if ((B0 = malloc(128 * r * p + 63)) == NULL) + goto err0; + B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63)); + if ((XY0 = malloc(256 * r + 64 + 63)) == NULL) + goto err1; + XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63)); +#ifndef MAP_ANON + if ((V0 = malloc(128 * r * N + 63)) == NULL) + goto err2; + V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63)); +#endif +#endif +#ifdef MAP_ANON + if ((V0 = mmap(NULL, 128 * r * N, PROT_READ | PROT_WRITE, +#ifdef MAP_NOCORE + MAP_ANON | MAP_PRIVATE | MAP_NOCORE, +#else + MAP_ANON | MAP_PRIVATE, +#endif + -1, 0)) == MAP_FAILED) + goto err2; + V = (uint32_t *)(V0); +#endif + + /* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */ + PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r); + + /* 2: for i = 0 to p - 1 do */ + for (i = 0; i < p; i++) { + /* 3: B_i <-- MF(B_i, N) */ + smix(&B[i * 128 * r], r, N, V, XY); + } + + /* 5: DK <-- PBKDF2(P, B, 1, dkLen) */ + PBKDF2_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen); + + /* Free memory. */ +#ifdef MAP_ANON + if (munmap(V0, 128 * r * N)) + goto err2; +#else + free(V0); +#endif + free(XY0); + free(B0); + + /* Success! */ + return (0); + +err2: + free(XY0); +err1: + free(B0); +err0: + /* Failure! */ + return (-1); +} diff --git a/outside/scrypt/crypto_scrypt.h b/outside/scrypt/crypto_scrypt.h new file mode 100644 index 000000000..b88be09d8 --- /dev/null +++ b/outside/scrypt/crypto_scrypt.h @@ -0,0 +1,51 @@ +/*- + * Copyright 2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ +#ifndef _CRYPTO_SCRYPT_H_ +#define _CRYPTO_SCRYPT_H_ + +#include +#include + +void smix(uint8_t *, size_t, uint64_t, void *, void *); +void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, + uint64_t, uint8_t *, size_t); + +/** + * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): + * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r, + * p, buflen) and write the result into buf. The parameters r, p, and buflen + * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N + * must be a power of 2 greater than 1. + * + * Return 0 on success; or -1 on error. + */ +int crypto_scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t, + uint32_t, uint32_t, uint8_t *, size_t); + +#endif /* !_CRYPTO_SCRYPT_H_ */ diff --git a/outside/scrypt/sha256.c b/outside/scrypt/sha256.c new file mode 100644 index 000000000..d2f915f1a --- /dev/null +++ b/outside/scrypt/sha256.c @@ -0,0 +1,411 @@ +/*- + * Copyright 2005,2007,2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +#include +#include + +#include "sysendian.h" + +#include "sha256.h" + +/* + * Encode a length len/4 vector of (uint32_t) into a length len vector of + * (unsigned char) in big-endian form. Assumes len is a multiple of 4. + */ +static void +be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len) +{ + size_t i; + + for (i = 0; i < len / 4; i++) + be32enc(dst + i * 4, src[i]); +} + +/* + * Decode a big-endian length len vector of (unsigned char) into a length + * len/4 vector of (uint32_t). Assumes len is a multiple of 4. + */ +static void +be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len) +{ + size_t i; + + for (i = 0; i < len / 4; i++) + dst[i] = be32dec(src + i * 4); +} + +/* Elementary functions used by SHA256 */ +#define Ch(x, y, z) ((x & (y ^ z)) ^ z) +#define Maj(x, y, z) ((x & (y | z)) | (y & z)) +#define SHR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << (32 - n))) +#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) + +/* SHA256 round function */ +#define RND(a, b, c, d, e, f, g, h, k) \ + t0 = h + S1(e) + Ch(e, f, g) + k; \ + t1 = S0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +/* Adjusted round function for rotating state */ +#define RNDr(S, W, i, k) \ + RND(S[(64 - i) % 8], S[(65 - i) % 8], \ + S[(66 - i) % 8], S[(67 - i) % 8], \ + S[(68 - i) % 8], S[(69 - i) % 8], \ + S[(70 - i) % 8], S[(71 - i) % 8], \ + W[i] + k) + +/* + * SHA256 block compression function. The 256-bit state is transformed via + * the 512-bit input block to produce a new state. + */ +static void +SHA256_Transform(uint32_t * state, const unsigned char block[64]) +{ + uint32_t W[64]; + uint32_t S[8]; + uint32_t t0, t1; + int i; + + /* 1. Prepare message schedule W. */ + be32dec_vect(W, block, 64); + for (i = 16; i < 64; i++) + W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; + + /* 2. Initialize working variables. */ + memcpy(S, state, 32); + + /* 3. Mix. */ + RNDr(S, W, 0, 0x428a2f98); + RNDr(S, W, 1, 0x71374491); + RNDr(S, W, 2, 0xb5c0fbcf); + RNDr(S, W, 3, 0xe9b5dba5); + RNDr(S, W, 4, 0x3956c25b); + RNDr(S, W, 5, 0x59f111f1); + RNDr(S, W, 6, 0x923f82a4); + RNDr(S, W, 7, 0xab1c5ed5); + RNDr(S, W, 8, 0xd807aa98); + RNDr(S, W, 9, 0x12835b01); + RNDr(S, W, 10, 0x243185be); + RNDr(S, W, 11, 0x550c7dc3); + RNDr(S, W, 12, 0x72be5d74); + RNDr(S, W, 13, 0x80deb1fe); + RNDr(S, W, 14, 0x9bdc06a7); + RNDr(S, W, 15, 0xc19bf174); + RNDr(S, W, 16, 0xe49b69c1); + RNDr(S, W, 17, 0xefbe4786); + RNDr(S, W, 18, 0x0fc19dc6); + RNDr(S, W, 19, 0x240ca1cc); + RNDr(S, W, 20, 0x2de92c6f); + RNDr(S, W, 21, 0x4a7484aa); + RNDr(S, W, 22, 0x5cb0a9dc); + RNDr(S, W, 23, 0x76f988da); + RNDr(S, W, 24, 0x983e5152); + RNDr(S, W, 25, 0xa831c66d); + RNDr(S, W, 26, 0xb00327c8); + RNDr(S, W, 27, 0xbf597fc7); + RNDr(S, W, 28, 0xc6e00bf3); + RNDr(S, W, 29, 0xd5a79147); + RNDr(S, W, 30, 0x06ca6351); + RNDr(S, W, 31, 0x14292967); + RNDr(S, W, 32, 0x27b70a85); + RNDr(S, W, 33, 0x2e1b2138); + RNDr(S, W, 34, 0x4d2c6dfc); + RNDr(S, W, 35, 0x53380d13); + RNDr(S, W, 36, 0x650a7354); + RNDr(S, W, 37, 0x766a0abb); + RNDr(S, W, 38, 0x81c2c92e); + RNDr(S, W, 39, 0x92722c85); + RNDr(S, W, 40, 0xa2bfe8a1); + RNDr(S, W, 41, 0xa81a664b); + RNDr(S, W, 42, 0xc24b8b70); + RNDr(S, W, 43, 0xc76c51a3); + RNDr(S, W, 44, 0xd192e819); + RNDr(S, W, 45, 0xd6990624); + RNDr(S, W, 46, 0xf40e3585); + RNDr(S, W, 47, 0x106aa070); + RNDr(S, W, 48, 0x19a4c116); + RNDr(S, W, 49, 0x1e376c08); + RNDr(S, W, 50, 0x2748774c); + RNDr(S, W, 51, 0x34b0bcb5); + RNDr(S, W, 52, 0x391c0cb3); + RNDr(S, W, 53, 0x4ed8aa4a); + RNDr(S, W, 54, 0x5b9cca4f); + RNDr(S, W, 55, 0x682e6ff3); + RNDr(S, W, 56, 0x748f82ee); + RNDr(S, W, 57, 0x78a5636f); + RNDr(S, W, 58, 0x84c87814); + RNDr(S, W, 59, 0x8cc70208); + RNDr(S, W, 60, 0x90befffa); + RNDr(S, W, 61, 0xa4506ceb); + RNDr(S, W, 62, 0xbef9a3f7); + RNDr(S, W, 63, 0xc67178f2); + + /* 4. Mix local working variables into global state */ + for (i = 0; i < 8; i++) + state[i] += S[i]; + + /* Clean the stack. */ + memset(W, 0, 256); + memset(S, 0, 32); + t0 = t1 = 0; +} + +static unsigned char PAD[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* Add padding and terminating bit-count. */ +static void +SHA256_Pad(SHA256_CTX * ctx) +{ + unsigned char len[8]; + uint32_t r, plen; + + /* + * Convert length to a vector of bytes -- we do this now rather + * than later because the length will change after we pad. + */ + be32enc_vect(len, ctx->count, 8); + + /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ + r = (ctx->count[1] >> 3) & 0x3f; + plen = (r < 56) ? (56 - r) : (120 - r); + SHA256_Update(ctx, PAD, (size_t)plen); + + /* Add the terminating bit-count */ + SHA256_Update(ctx, len, 8); +} + +/* SHA-256 initialization. Begins a SHA-256 operation. */ +void +SHA256_Init(SHA256_CTX * ctx) +{ + + /* Zero bits processed so far */ + ctx->count[0] = ctx->count[1] = 0; + + /* Magic initialization constants */ + ctx->state[0] = 0x6A09E667; + ctx->state[1] = 0xBB67AE85; + ctx->state[2] = 0x3C6EF372; + ctx->state[3] = 0xA54FF53A; + ctx->state[4] = 0x510E527F; + ctx->state[5] = 0x9B05688C; + ctx->state[6] = 0x1F83D9AB; + ctx->state[7] = 0x5BE0CD19; +} + +/* Add bytes into the hash */ +void +SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) +{ + uint32_t bitlen[2]; + uint32_t r; + const unsigned char *src = in; + + /* Number of bytes left in the buffer from previous updates */ + r = (ctx->count[1] >> 3) & 0x3f; + + /* Convert the length into a number of bits */ + bitlen[1] = ((uint32_t)len) << 3; + bitlen[0] = (uint32_t)(len >> 29); + + /* Update number of bits */ + if ((ctx->count[1] += bitlen[1]) < bitlen[1]) + ctx->count[0]++; + ctx->count[0] += bitlen[0]; + + /* Handle the case where we don't need to perform any transforms */ + if (len < 64 - r) { + memcpy(&ctx->buf[r], src, len); + return; + } + + /* Finish the current block */ + memcpy(&ctx->buf[r], src, 64 - r); + SHA256_Transform(ctx->state, ctx->buf); + src += 64 - r; + len -= 64 - r; + + /* Perform complete blocks */ + while (len >= 64) { + SHA256_Transform(ctx->state, src); + src += 64; + len -= 64; + } + + /* Copy left over data into buffer */ + memcpy(ctx->buf, src, len); +} + +/* + * SHA-256 finalization. Pads the input data, exports the hash value, + * and clears the context state. + */ +void +SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx) +{ + + /* Add padding */ + SHA256_Pad(ctx); + + /* Write the hash */ + be32enc_vect(digest, ctx->state, 32); + + /* Clear the context state */ + memset((void *)ctx, 0, sizeof(*ctx)); +} + +/* Initialize an HMAC-SHA256 operation with the given key. */ +void +HMAC_SHA256_Init(HMAC_SHA256_CTX * ctx, const void * _K, size_t Klen) +{ + unsigned char pad[64]; + unsigned char khash[32]; + const unsigned char * K = _K; + size_t i; + + /* If Klen > 64, the key is really SHA256(K). */ + if (Klen > 64) { + SHA256_Init(&ctx->ictx); + SHA256_Update(&ctx->ictx, K, Klen); + SHA256_Final(khash, &ctx->ictx); + K = khash; + Klen = 32; + } + + /* Inner SHA256 operation is SHA256(K xor [block of 0x36] || data). */ + SHA256_Init(&ctx->ictx); + memset(pad, 0x36, 64); + for (i = 0; i < Klen; i++) + pad[i] ^= K[i]; + SHA256_Update(&ctx->ictx, pad, 64); + + /* Outer SHA256 operation is SHA256(K xor [block of 0x5c] || hash). */ + SHA256_Init(&ctx->octx); + memset(pad, 0x5c, 64); + for (i = 0; i < Klen; i++) + pad[i] ^= K[i]; + SHA256_Update(&ctx->octx, pad, 64); + + /* Clean the stack. */ + memset(khash, 0, 32); +} + +/* Add bytes to the HMAC-SHA256 operation. */ +void +HMAC_SHA256_Update(HMAC_SHA256_CTX * ctx, const void *in, size_t len) +{ + + /* Feed data to the inner SHA256 operation. */ + SHA256_Update(&ctx->ictx, in, len); +} + +/* Finish an HMAC-SHA256 operation. */ +void +HMAC_SHA256_Final(unsigned char digest[32], HMAC_SHA256_CTX * ctx) +{ + unsigned char ihash[32]; + + /* Finish the inner SHA256 operation. */ + SHA256_Final(ihash, &ctx->ictx); + + /* Feed the inner hash to the outer SHA256 operation. */ + SHA256_Update(&ctx->octx, ihash, 32); + + /* Finish the outer SHA256 operation. */ + SHA256_Final(digest, &ctx->octx); + + /* Clean the stack. */ + memset(ihash, 0, 32); +} + +/** + * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): + * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and + * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). + */ +void +PBKDF2_SHA256(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, + size_t saltlen, uint64_t c, uint8_t * buf, size_t dkLen) +{ + HMAC_SHA256_CTX PShctx, hctx; + size_t i; + uint8_t ivec[4]; + uint8_t U[32]; + uint8_t T[32]; + uint64_t j; + int k; + size_t clen; + + /* Compute HMAC state after processing P and S. */ + HMAC_SHA256_Init(&PShctx, passwd, passwdlen); + HMAC_SHA256_Update(&PShctx, salt, saltlen); + + /* Iterate through the blocks. */ + for (i = 0; i * 32 < dkLen; i++) { + /* Generate INT(i + 1). */ + be32enc(ivec, (uint32_t)(i + 1)); + + /* Compute U_1 = PRF(P, S || INT(i)). */ + memcpy(&hctx, &PShctx, sizeof(HMAC_SHA256_CTX)); + HMAC_SHA256_Update(&hctx, ivec, 4); + HMAC_SHA256_Final(U, &hctx); + + /* T_i = U_1 ... */ + memcpy(T, U, 32); + + for (j = 2; j <= c; j++) { + /* Compute U_j. */ + HMAC_SHA256_Init(&hctx, passwd, passwdlen); + HMAC_SHA256_Update(&hctx, U, 32); + HMAC_SHA256_Final(U, &hctx); + + /* ... xor U_j ... */ + for (k = 0; k < 32; k++) + T[k] ^= U[k]; + } + + /* Copy as many bytes as necessary into buf. */ + clen = dkLen - i * 32; + if (clen > 32) + clen = 32; + memcpy(&buf[i * 32], T, clen); + } + + /* Clean PShctx, since we never called _Final on it. */ + memset(&PShctx, 0, sizeof(HMAC_SHA256_CTX)); +} diff --git a/outside/scrypt/sha256.h b/outside/scrypt/sha256.h new file mode 100644 index 000000000..289a5232f --- /dev/null +++ b/outside/scrypt/sha256.h @@ -0,0 +1,62 @@ +/*- + * Copyright 2005,2007,2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/libmd/sha256.h,v 1.2 2006/01/17 15:35:56 phk Exp $ + */ + +#ifndef _SHA256_H_ +#define _SHA256_H_ + +#include + +#include + +typedef struct SHA256Context { + uint32_t state[8]; + uint32_t count[2]; + unsigned char buf[64]; +} SHA256_CTX; + +typedef struct HMAC_SHA256Context { + SHA256_CTX ictx; + SHA256_CTX octx; +} HMAC_SHA256_CTX; + +void SHA256_Init(SHA256_CTX *); +void SHA256_Update(SHA256_CTX *, const void *, size_t); +void SHA256_Final(unsigned char [32], SHA256_CTX *); +void HMAC_SHA256_Init(HMAC_SHA256_CTX *, const void *, size_t); +void HMAC_SHA256_Update(HMAC_SHA256_CTX *, const void *, size_t); +void HMAC_SHA256_Final(unsigned char [32], HMAC_SHA256_CTX *); + +/** + * PBKDF2_SHA256(passwd, passwdlen, salt, saltlen, c, buf, dkLen): + * Compute PBKDF2(passwd, salt, c, dkLen) using HMAC-SHA256 as the PRF, and + * write the output to buf. The value dkLen must be at most 32 * (2^32 - 1). + */ +void PBKDF2_SHA256(const uint8_t *, size_t, const uint8_t *, size_t, + uint64_t, uint8_t *, size_t); + +#endif /* !_SHA256_H_ */ diff --git a/outside/scrypt/sysendian.h b/outside/scrypt/sysendian.h new file mode 100644 index 000000000..207fb0693 --- /dev/null +++ b/outside/scrypt/sysendian.h @@ -0,0 +1,129 @@ +/*- + * Copyright 2007-2009 Colin Percival + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ +#ifndef _SYSENDIAN_H_ +#define _SYSENDIAN_H_ + +#if defined(U3_OS_bsd) +#include +#else +#include + +static inline uint32_t +be32dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) + + ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24)); +} + +static inline void +be32enc(void *pp, uint32_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[3] = x & 0xff; + p[2] = (x >> 8) & 0xff; + p[1] = (x >> 16) & 0xff; + p[0] = (x >> 24) & 0xff; +} + +static inline uint64_t +be64dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) + + ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) + + ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) + + ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56)); +} + +static inline void +be64enc(void *pp, uint64_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[7] = x & 0xff; + p[6] = (x >> 8) & 0xff; + p[5] = (x >> 16) & 0xff; + p[4] = (x >> 24) & 0xff; + p[3] = (x >> 32) & 0xff; + p[2] = (x >> 40) & 0xff; + p[1] = (x >> 48) & 0xff; + p[0] = (x >> 56) & 0xff; +} + +static inline uint32_t +le32dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) + + ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24)); +} + +static inline void +le32enc(void *pp, uint32_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[0] = x & 0xff; + p[1] = (x >> 8) & 0xff; + p[2] = (x >> 16) & 0xff; + p[3] = (x >> 24) & 0xff; +} + +static inline uint64_t +le64dec(const void *pp) +{ + const uint8_t *p = (uint8_t const *)pp; + + return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) + + ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) + + ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) + + ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56)); +} + +static inline void +le64enc(void *pp, uint64_t x) +{ + uint8_t * p = (uint8_t *)pp; + + p[0] = x & 0xff; + p[1] = (x >> 8) & 0xff; + p[2] = (x >> 16) & 0xff; + p[3] = (x >> 24) & 0xff; + p[4] = (x >> 32) & 0xff; + p[5] = (x >> 40) & 0xff; + p[6] = (x >> 48) & 0xff; + p[7] = (x >> 56) & 0xff; +} +#endif +#endif /* !_SYSENDIAN_H_ */ From 7fb84652e888255a070396fafe6e3744fc9179fa Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Wed, 6 May 2015 18:25:58 -0700 Subject: [PATCH 23/24] Run test in optimized. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f6042e2e0..c83c8a0d7 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ MDEFINES=-DU3_OS_$(OS) -DU3_OS_ENDIAN_$(ENDIAN) -D U3_LIB=\"$(LIB)\" # NOTFORCHECKIN - restore -O3 # -DGHETTO -CFLAGS= $(COSFLAGS) -g -msse3 -ffast-math \ +CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ -funsigned-char \ -I/usr/local/include \ -I/opt/local/include \ From 0ca2fc94de56cf6b9c8f961ebf750af5d256cf7b Mon Sep 17 00:00:00 2001 From: Philip C Monk Date: Wed, 6 May 2015 22:25:41 -0400 Subject: [PATCH 24/24] added space profiling tools --- i/c/motes.h | 1 + v/reck.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++ v/unix.c | 12 ++--- 3 files changed, 134 insertions(+), 6 deletions(-) diff --git a/i/c/motes.h b/i/c/motes.h index 5642ef9de..e67ce0b21 100644 --- a/i/c/motes.h +++ b/i/c/motes.h @@ -652,6 +652,7 @@ # define c3__map c3_s3('m','a','p') # define c3__marg c3_s4('m','a','r','g') # define c3__mark c3_s4('m','a','r','k') +# define c3__mass c3_s4('m','a','s','s') # define c3__marn c3_s4('m','a','r','n') # define c3__mash c3_s4('m','a','s','h') # define c3__mast c3_s4('m','a','s','t') diff --git a/v/reck.c b/v/reck.c index dea25c83e..7d4a6eac4 100644 --- a/v/reck.c +++ b/v/reck.c @@ -66,6 +66,120 @@ _reck_lily(u3_noun fot, u3_noun txt, c3_l* tid_l) } } +/* _reck_spac(): print n spaces. +*/ +void _reck_spac(c3_w n) +{ + for (; n > 0; n--) + uL(fprintf(uH," ")); +} + +/* _reck_print_memory: print memory amount. cf u3a_print_memory(). +*/ +void +_reck_print_memory(c3_w wor_w) +{ + c3_w byt_w = (wor_w * 4); + c3_w gib_w = (byt_w / 1000000000); + c3_w mib_w = (byt_w % 1000000000) / 1000000; + c3_w kib_w = (byt_w % 1000000) / 1000; + c3_w bib_w = (byt_w % 1000); + + if ( gib_w ) { + uL(fprintf(uH, "GB/%d.%03d.%03d.%03d\r\n", + gib_w, mib_w, kib_w, bib_w)); + } + else if ( mib_w ) { + uL(fprintf(uH, "MB/%d.%03d.%03d\r\n", mib_w, kib_w, bib_w)); + } + else if ( kib_w ) { + uL(fprintf(uH, "KB/%d.%03d\r\n", kib_w, bib_w)); + } + else { + uL(fprintf(uH, "B/%d\r\n", bib_w)); + } +} + +/* _reck_meme_noun(): get memory usage, in words, of noun. RETAIN. +*/ +c3_w +_reck_meme_noun(u3p(u3h_root) hax, u3_noun non, c3_t dud) +{ + u3_weak got = u3h_git(hax, dud ? non & 0x7fffffff : non); + + if (u3_none != got) { + return 0; // I think? maybe 1 + } + else { + c3_w res; + + if (!(non & 0x80000000)) { + res = 1; + } + if (_(u3ud(non))) { + res = 2 + u3r_met(5, non); + } + else { + res = 1 + + _reck_meme_noun(hax, u3h(non), dud) + + _reck_meme_noun(hax, u3t(non), dud); + } + + u3h_put(hax, dud ? non & 0x7fffffff : non, res); + + return res; + } +} + +/* _reck_meme_prof(): print memory profile. RETAIN. +*/ +void +_reck_meme_prof(u3p(u3h_root) hax, c3_w den, u3_noun mas) +{ + u3_noun h_mas, t_mas; + + if (c3n == u3r_cell(mas, &h_mas, &t_mas)) { + _reck_spac(den); + uL(fprintf(uH, "mistyped mass\r\n")); + return; + } + if (c3y == h_mas) { + _reck_spac(den); + _reck_print_memory(_reck_meme_noun(hax, t_mas, false)); + _reck_spac(den); + _reck_print_memory(_reck_meme_noun(hax, t_mas, true)); + } + else if (c3n == h_mas) { + u3_noun it_mas, tt_mas, pit_mas, qit_mas; + while (u3_nul != t_mas) + { + _reck_spac(den); + if (c3n == u3r_cell(t_mas, &it_mas, &tt_mas)) { + uL(fprintf(uH, "mistyped mass list\r\n")); + return; + } + else if (c3n == u3r_cell(it_mas, &pit_mas, &qit_mas)) { + uL(fprintf(uH, "mistyped mass list element\r\n")); + return; + } + else { + c3_c* pit_c = u3m_pretty(pit_mas); + uL(fprintf(uH, "%s\r\n", pit_c)); + free(pit_c); + + _reck_meme_prof(hax, den+2, qit_mas); + + t_mas = tt_mas; + } + } + } + else { + _reck_spac(den); + uL(fprintf(uH, "mistyped mass head\r\n")); + return; + } +} + /* _reck_kick_term(): apply terminal outputs. */ static u3_noun @@ -110,6 +224,19 @@ _reck_kick_term(u3_noun pox, c3_l tid_l, u3_noun fav) uL(fprintf(uH, "kick: init: %s\n", nam_c)); free(nam_c); u3z(pox); u3z(hox); u3z(fav); return c3y; } break; + + case c3__mass: p_fav = u3t(fav); + { + uL(fprintf(uH, "memory profile:\r\n")); + + u3p(u3h_root) hax = u3h_new(); + + _reck_meme_prof(hax, 0, p_fav); + + u3h_free(hax); + + u3z(pox); u3z(fav); return c3y; + } break; } c3_assert(!"not reached"); return 0; } diff --git a/v/unix.c b/v/unix.c index b67fdd6cf..f411838d1 100644 --- a/v/unix.c +++ b/v/unix.c @@ -666,9 +666,9 @@ _unix_dir_update(u3_udir* dir_u, DIR* rid_u) /* unix_load(): load a file as a cage * - * return value of c3__none means delete, u3_nul means no change + * return value of u3_none means delete, u3_nul means no change */ -static u3_noun +static u3_weak _unix_load(u3_ufil* fil_u) { struct stat buf_u; @@ -684,7 +684,7 @@ _unix_load(u3_ufil* fil_u) if ( ENOENT != errno ) { uL(fprintf(uH, "error loading %s: %s\n", fil_u->pax_c, strerror(errno))); } - return c3__none; + return u3_none; } fln_w = buf_u.st_size; pad_y = c3_malloc(fln_w); @@ -779,7 +779,7 @@ _unix_save(c3_c* pax_c, u3_atom oat) /* _unix_file_load(): load a file by watcher. */ -static u3_noun +static u3_weak _unix_file_load(u3_ufil* fil_u) { return _unix_load(fil_u); @@ -938,8 +938,8 @@ _unix_dir_khan(u3_udir* dir_u) for ( fil_u = dir_u->fil_u; fil_u; fil_u = fil_u->nex_u ) { u3_noun wib = _unix_file_name(fil_u); - u3_noun baw = _unix_file_load(fil_u); - u3_noun wol = (c3__none == baw ? u3nc(u3_nul, u3_nul) : + u3_weak baw = _unix_file_load(fil_u); + u3_noun wol = (u3_none == baw ? u3nc(u3_nul, u3_nul) : u3_nul == baw ? u3_nul : u3nt(u3_nul, u3_nul, baw)); pam = _unix_dir_khan_file(pam, wib, wol);