int main() { uint8_t key[1024]; char *password = "******"; char *salt = "salt"; int i, fails; struct test *t; fails = 0; memset(key, 0, 1024); bcrypt_pbkdf("password", 8, "salt", 4, key, 88, 4); if (key[88] || key[89] || key[90]) { printf("OVERWRITE\n"); fails++; } for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { t = &tests[i]; bcrypt_pbkdf(t->password, t->passlen, t->salt, t->saltlen, key, t->keylen, t->rounds); if (memcmp(key, t->key, t->keylen) != 0) { printf("test %d FAILED\n", i); printf("expected:\n"); printkey(t->key, t->keylen); printf("result:\n"); printkey(key, t->keylen); fails++; } } return fails; }
void executePWSetupPress(int choice, int *inputBoxPressed, int *buttonPressed, int * sdBoxPressed) { if (*sdBoxPressed == 1) { if (choice == 0) { char newPassword[80]; strcpy(newPassword, globalCurrentPage->inputBoxes[0].inputBuf); // append '$' to signal end of password sprintf(newPassword, "%s%s", newPassword, "$"); keygen(key, newPassword, strlen(newPassword)); if (writeToSD(key, KEYFILE) == 0) { greenLEDS = 0xff; } else { redLEDS = 0xff; } writeToSD(newPassword, "password.txt"); printkey(key); } if (choice == 1) { if (writeToSD("E", "passMode.txt") == 0) { greenLEDS = 0xff; ; } } if (choice == 2) { if (writeToSD("D", "passMode.txt") == 0) { redLEDS = 0xff; } } } if (*inputBoxPressed == 1) { printf("input box choice: %d \n", choice); keys->keyboard.curInputBoxIndex = choice; keys->keyboard.caller = globalCurrentPage; strcpy(keys->keyboard.buffer, globalCurrentPage->inputBoxes[choice].inputBuf); keys->keyboard.bufCount = strlen( globalCurrentPage->inputBoxes[choice].inputBuf); strcpy(keys->objects[0].objectText, globalCurrentPage->inputBoxes[choice].inputBuf); keys->objects[0].captionLength = strlen( globalCurrentPage->inputBoxes[choice].inputBuf); globalCurrentPage = keys; } if (*buttonPressed == 1) { Button theButton = globalCurrentPage->buttons[choice]; globalCurrentPage = theButton.targetPage; } }
main (int argc, char *argv[]) { char directory[255+1]; tsigkey_t key; progname = argv[0]; directory[0] = '\0'; if ( --argc == 0 ) parse_keyconf ("/var/named/named.conf", directory, sizeof (directory), &key, NULL); else parse_keyconf (argv[1], directory, sizeof (directory), &key, argv[2]); printkey (&key); }
/*This function prints out a Dict, it takes as its arguments to print(void* item) functions, one to print the keys, and one to print the values. */ void dprint(Dict dictionary,void (*printkey)(void* item),void (*printvalue)(void* item)) { int i; printf("Length: %d\n",getLength(dictionary)); printf("Capacity: %d\n",dictionary->capacity); for(i=0;i<getLength(dictionary);i++) { printf("Key %d: <",i); printkey(gget(dictionary->keys,i)); printf(","); printvalue(gget(dictionary->values,i)); printf(">\n"); } }
void printparentchild(capfs::TripleHashParentChild const pc,std::string name) { printkey(pc.parent(),name + "::parent"); printkey(pc.child(),name + "::child"); }
/*===================================== * process_fam -- process indi record * checking in pass 1, fixing in pass 2 *===================================*/ static void process_fam (RECORD rec) { NODE fam0, fam1; NODE fref1, husb1, wife1, chil1, rest1; NODE node1; INT members = 0; BOOLEAN altered=FALSE; BOOLEAN needfix=FALSE; CNSTRING key = nzkey(rec); fam0 = nztop(rec); if (todo.pass==1) { fam1 = fam0; } else { fam1 = copy_node_subtree(fam0); } split_fam(fam1, &fref1, &husb1, &wife1, &chil1, &rest1); /* check refns */ for (node1 = fref1; node1; node1 = nsibling(node1)) { /* STRING refn=nval(node1); */ /* TO DO: verify that refn is in db */ } /* check husbs */ for (node1 = husb1; node1; node1 = nsibling(node1)) { STRING husbkey=rmvat(nval(node1)); NODE husb = qkey_to_indi(husbkey); members++; if (!husb) { if (todo.pass == 1) { report_error(ERR_BADHUSBREF , _("Bad HUSB reference (%s) in family %s") , husbkey, key); needfix=TRUE; } else { if (fix_bad_pointer(key, rec, node1)) { report_fix(ERR_BADHUSBREF , _("Fixed Bad HUSB reference (%s) in family %s") , husbkey, key); altered=TRUE; } } } else { /* look for family (key) in husb */ if (!find_xref(key, husb, "FAMS", NULL)) { report_error(ERR_EXTRAHUSB , _("Improper HUSB (%s) in family (%s)") , husbkey, key); } } } /* check wives */ for (node1 = wife1; node1; node1 = nsibling(node1)) { STRING wifekey=rmvat(nval(node1)); NODE wife = qkey_to_indi(wifekey); members++; if (!wife) { if (todo.pass == 1) { report_error(ERR_BADWIFEREF , _("Bad wife reference (%s) in family %s") , wifekey, key); needfix=TRUE; } else { if (fix_bad_pointer(key, rec, node1)) { report_fix(ERR_BADWIFEREF , _("Fixed Bad wife reference (%s) in family %s") , printkey(wifekey), key); altered=TRUE; } } } else { /* look for family (key) in wife */ if (!find_xref(key, wife, "FAMS", NULL)) { report_error(ERR_EXTRAWIFE , _("Improper wife (%s) in family (%s)") , printkey(wifekey), key); } } } /* check children */ for (node1 = chil1; node1; node1 = nsibling(node1)) { STRING chilkey=rmvat(nval(node1)); NODE child = qkey_to_indi(chilkey); members++; if (!child) { if (todo.pass == 1) { report_error(ERR_BADCHILDREF , _("Bad child reference (%s) in family %s") , printkey(chilkey), key); needfix=TRUE; } else { if (fix_bad_pointer(key, rec, node1)) { report_fix(ERR_BADCHILDREF , _("Fixed bad child reference (%s) in family %s") , printkey(chilkey), key); altered=TRUE; } } } else { /* look for family (key) in child */ if (!find_xref(key, child, "FAMC", NULL)) { report_error(ERR_EXTRACHILD , _("Improper child: Child (%s) without FAMC reference to family (%s)") , printkey(chilkey), key); } } } join_fam(fam1, fref1, husb1, wife1, chil1, rest1); /* check for undersized family */ if (!members) { report_error(ERR_EMPTYFAM, _("Empty family (%s)"), key); } else if (members == 1) { report_error(ERR_SOLOFAM, _("Single person family (%s)"), key); } if (altered) { /* must normalize, as some lineage references may have been altered to non-lineage tags to fix broken pointers */ normalize_fam(fam1); /* write to database */ replace_fam(fam0, fam1); } else if (needfix) { enqueue_list(tofix, strsave(key)); } }
static void HandleEvents(void) { const int t = 0; // always just use the current time. SDL_Event e; const char *p = NULL; int key = 0; if (screen == NULL) return; // no SDL context. if (cls.keyCatchers == 0) { if (sdlrepeatenabled) { SDL_EnableKeyRepeat(0, 0); sdlrepeatenabled = qfalse; } } else { if (!sdlrepeatenabled) { SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); sdlrepeatenabled = qtrue; } } while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_KEYDOWN: printkey(&e); p = XLateKey(&e.key.keysym, &key); if (key) { Sys_QueEvent( t, SE_KEY, key, qtrue, 0, NULL ); } if (p) { while (*p) { Sys_QueEvent( t, SE_CHAR, *p++, 0, 0, NULL ); } } break; case SDL_KEYUP: XLateKey(&e.key.keysym, &key); Sys_QueEvent( t, SE_KEY, key, qfalse, 0, NULL ); break; case SDL_MOUSEMOTION: if (mouse_active) { Sys_QueEvent( t, SE_MOUSE, e.motion.xrel, e.motion.yrel, 0, NULL ); } break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { unsigned char b; switch (e.button.button) { case 1: b = K_MOUSE1; break; case 2: b = K_MOUSE3; break; case 3: b = K_MOUSE2; break; case 4: b = K_MWHEELUP; break; case 5: b = K_MWHEELDOWN; break; case 6: b = K_MOUSE4; break; case 7: b = K_MOUSE5; break; default: b = K_AUX1 + (e.button.button - 8)%16; break; } Sys_QueEvent( t, SE_KEY, b, (e.type == SDL_MOUSEBUTTONDOWN?qtrue:qfalse), 0, NULL ); } break; case SDL_QUIT: Sys_Quit(); break; } } }
main() { int loop; int i; gaudry_init(); for (loop = 0;loop < 100;++loop) { random16(k); printf("tk="); print16(k); printf(";\n"); gaudry_todouble(x,k); printf("tx="); printdouble(x); printf(";\n"); printf("(tx-tk)%(2^127-1)\n"); randomdouble(x); randomdouble(y); printf("tx="); printdouble(x); printf(";\n"); printf("ty="); printdouble(y); printf(";\n"); gaudry_mult(z,x,y); printf("tz="); printdouble(z); printf(";\n"); printf("(tx*ty-tz)%(2^127-1)\n"); randomdouble(x); printf("tx="); printdouble(x); printf(";\n"); gaudry_recip(z,x); printf("tz="); printdouble(z); printf(";\n"); printf("(tx*tz-1)%(2^127-1)\n"); gaudry_fromdouble(k,z); printf("tk="); print16(k); printf(";\n"); printf("(tz-tk)%(2^127-1)\n"); randomdouble(x); printf("x0="); printdouble(x); printf(";\n"); randomdouble(x + 5); printf("x1="); printdouble(x + 5); printf(";\n"); randomdouble(x + 10); printf("x2="); printdouble(x + 10); printf(";\n"); randomdouble(x + 15); printf("x3="); printdouble(x + 15); printf(";\n"); gaudry_hadamard(z,x); printf("z0="); printdouble(z); printf(";\n"); printf("z1="); printdouble(z + 5); printf(";\n"); printf("z2="); printdouble(z + 10); printf(";\n"); printf("z3="); printdouble(z + 15); printf(";\n"); printf("(x0+x1+x2+x3)-z0\n"); printf("(x0+x1-x2-x3)-z1\n"); printf("(x0-x1+x2-x3)-z2\n"); printf("(x0-x1-x2+x3)-z3\n"); } gaudry_surface_specify(a,b,c,d); printf("p=2^127-1;\n"); printf("a=Mod("); print16(a); printf(",p);\n"); printf("b=Mod("); print16(b); printf(",p);\n"); printf("c=Mod("); print16(c); printf(",p);\n"); printf("d=Mod("); print16(d); printf(",p);\n"); printf("qx1=Mod("); print16(x1str); printf(",p);\n"); printf("qy1=Mod("); print16(y1str); printf(",p);\n"); printf("qz1=Mod("); print16(z1str); printf(",p);\n"); printf("qt1=Mod("); print16(t1str); printf(",p);\n"); printf("R1=[qx1,qy1,qz1,qt1];\n"); printf("H(Q)=Q*[1,1,1,1;1,1,-1,-1;1,-1,1,-1;1,-1,-1,1]\n"); printf("AA = H([a*a,b*b,c*c,d*d])[1]/4;\n"); printf("BB = H([a*a,b*b,c*c,d*d])[2]/4;\n"); printf("CC = H([a*a,b*b,c*c,d*d])[3]/4;\n"); printf("DD = H([a*a,b*b,c*c,d*d])[4]/4;\n"); printf("e = 256 * a*b*c*d *AA*BB*CC*DD / ((a*a*d*d-b*b*c*c)*(a*a*c*c-b*b*d*d)*(a*a*b*b-c*c*d*d));\n"); printf("f = (a*a*a*a - b*b*b*b - c*c*c*c + d*d*d*d) / (a*a*d*d - b*b*c*c);\n"); printf("g = (a*a*a*a - b*b*b*b + c*c*c*c - d*d*d*d) / (a*a*c*c - b*b*d*d);\n"); printf("h = (a*a*a*a + b*b*b*b - c*c*c*c - d*d*d*d) / (a*a*b*b - c*c*d*d);\n"); printf("C = x^4+y^4+z^4+t^4 + 2*e*x*y*z*t - f*(x^2*t^2+y^2*z^2) - g*(x^2*z^2+y^2*t^2) - h*(x^2*y^2+z^2*t^2);\n"); printf("square(Q)=[Q[1]^2,Q[2]^2,Q[3]^2,Q[4]^2]\n"); printf("ABC(Q)=[Q[1],Q[2]*AA/BB,Q[3]*AA/CC,Q[4]*AA/DD]\n"); printf("mult(P,Q)=[P[1]*Q[1],P[2]*Q[2],P[3]*Q[3],P[4]*Q[4]]\n"); printf("abc(Q)=[Q[1],Q[2]*a/b,Q[3]*a/c,Q[4]*a/d]\n"); printf("double(Q)=abc(H(ABC(square(H(square(Q))))))\n"); printf("divide(P,Q)=[P[1]/Q[1],P[2]/Q[2],P[3]/Q[3],P[4]/Q[4]]\n"); printf("dividescaled(Q,Q1)=[Q[1],Q[2]*Q1[1]/Q1[2],Q[3]*Q1[1]/Q1[3],Q[4]*Q1[1]/Q1[4]]\n"); printf("add(Q2,Q3,Q1)=dividescaled(H(ABC(mult(H(square(Q2)),H(square(Q3))))),Q1)\n"); printf("onsurface(Q)=subst(subst(subst(subst(C,x,Q[1]),y,Q[2]),z,Q[3]),t,Q[4])\n"); printf("doubleadd(Z,Q1)=[double(Z[1]),add(Z[1],Z[2],Q1)]\n"); printf("flip(Z,bit)=[Z[2]*bit+Z[1]*(1-bit),Z[1]*bit+Z[2]*(1-bit)]\n"); printf("doubleaddflip(Z,Q1,bit)=flip(doubleadd(flip(Z,bit),Q1),bit)\n"); printf("ladder(Q1,n)=if(n==0,[[a,b,c,d],Q1],doubleaddflip(ladder(Q1,floor(n/2)),Q1,n%2))\n"); printf("scalarmult(Q1,n)=ladder(Q1,n)[1]\n"); gaudry_todouble(q1 + 0,x1str); gaudry_todouble(q1 + 5,y1str); gaudry_todouble(q1 + 10,z1str); gaudry_todouble(q1 + 15,t1str); printf("Q1="); printpoint(q1); printf(";\n"); printf("lift(onsurface(Q1))\n"); printf("lift((Q1-R1)[1])\n"); printf("lift((Q1-R1)[2])\n"); printf("lift((Q1-R1)[3])\n"); printf("lift((Q1-R1)[4])\n"); for (loop = 0;loop < 1000;++loop) { for (i = 0;i < 32;++i) alicesecret[i] = random(); printf("AK="); print32(alicesecret); printf(";\n"); gaudry(alicepublic,alicesecret,basepoint); printf("AP="); printkey(alicepublic); printf(";\n"); printf("T=scalarmult(Q1,AK);\n"); printf("lift(T[1]/T[2]-AP[1])\n"); printf("lift(T[1]/T[3]-AP[2])\n"); printf("lift(T[1]/T[4]-AP[3])\n"); for (i = 0;i < 32;++i) bobsecret[i] = random(); printf("BK="); print32(bobsecret); printf(";\n"); gaudry(bobpublic,bobsecret,basepoint); printf("BP="); printkey(bobpublic); printf(";\n"); printf("T=scalarmult(Q1,BK);\n"); printf("lift(T[1]/T[2]-BP[1])\n"); printf("lift(T[1]/T[3]-BP[2])\n"); printf("lift(T[1]/T[4]-BP[3])\n"); gaudry(aliceshared,alicesecret,bobpublic); gaudry(bobshared,bobsecret,alicepublic); printf("AS="); printkey(aliceshared); printf(";\n"); printf("BS="); printkey(bobshared); printf(";\n"); printf("lift(AS[1]-BS[1])\n"); printf("lift(AS[2]-BS[2])\n"); printf("lift(AS[3]-BS[3])\n"); printf("T=scalarmult(Q1,AK*BK);\n"); printf("lift(T[1]/T[2]-AS[1])\n"); printf("lift(T[1]/T[3]-AS[2])\n"); printf("lift(T[1]/T[4]-AS[3])\n"); } return 0; }
void test_dr_dk () { static const struct { unsigned char keydata[KEYLENGTH]; int usage_len; unsigned char usage[8]; } derive_tests[] = { { { 0xdc, 0xe0, 0x6b, 0x1f, 0x64, 0xc8, 0x57, 0xa1, 0x1c, 0x3d, 0xb5, 0x7c, 0x51, 0x89, 0x9b, 0x2c, 0xc1, 0x79, 0x10, 0x08, 0xce, 0x97, 0x3b, 0x92, }, 5, { 0x00, 0x00, 0x00, 0x01, 0x55 }, }, { { 0x5e, 0x13, 0xd3, 0x1c, 0x70, 0xef, 0x76, 0x57, 0x46, 0x57, 0x85, 0x31, 0xcb, 0x51, 0xc1, 0x5b, 0xf1, 0x1c, 0xa8, 0x2c, 0x97, 0xce, 0xe9, 0xf2, }, 5, { 0x00, 0x00, 0x00, 0x01, 0xaa }, }, { { 0x98, 0xe6, 0xfd, 0x8a, 0x04, 0xa4, 0xb6, 0x85, 0x9b, 0x75, 0xa1, 0x76, 0x54, 0x0b, 0x97, 0x52, 0xba, 0xd3, 0xec, 0xd6, 0x10, 0xa2, 0x52, 0xbc, }, 5, { 0x00, 0x00, 0x00, 0x01, 0x55 }, }, { { 0x62, 0x2a, 0xec, 0x25, 0xa2, 0xfe, 0x2c, 0xad, 0x70, 0x94, 0x68, 0x0b, 0x7c, 0x64, 0x94, 0x02, 0x80, 0x08, 0x4c, 0x1a, 0x7c, 0xec, 0x92, 0xb5, }, 5, { 0x00, 0x00, 0x00, 0x01, 0xaa }, }, { { 0xd3, 0xf8, 0x29, 0x8c, 0xcb, 0x16, 0x64, 0x38, 0xdc, 0xb9, 0xb9, 0x3e, 0xe5, 0xa7, 0x62, 0x92, 0x86, 0xa4, 0x91, 0xf8, 0x38, 0xf8, 0x02, 0xfb, }, 8, { 'k', 'e', 'r', 'b', 'e', 'r', 'o', 's' }, }, { { 0xb5, 0x5e, 0x98, 0x34, 0x67, 0xe5, 0x51, 0xb3, 0xe5, 0xd0, 0xe5, 0xb6, 0xc8, 0x0d, 0x45, 0x76, 0x94, 0x23, 0xa8, 0x73, 0xdc, 0x62, 0xb3, 0x0e, }, 7, { 'c', 'o', 'm', 'b', 'i', 'n', 'e', }, }, { { 0xc1, 0x08, 0x16, 0x49, 0xad, 0xa7, 0x43, 0x62, 0xe6, 0xa1, 0x45, 0x9d, 0x01, 0xdf, 0xd3, 0x0d, 0x67, 0xc2, 0x23, 0x4c, 0x94, 0x07, 0x04, 0xda, }, 5, { 0x00, 0x00, 0x00, 0x01, 0x55 }, }, { { 0x5d, 0x15, 0x4a, 0xf2, 0x38, 0xf4, 0x67, 0x13, 0x15, 0x57, 0x19, 0xd5, 0x5e, 0x2f, 0x1f, 0x79, 0x0d, 0xd6, 0x61, 0xf2, 0x79, 0xa7, 0x91, 0x7c, }, 5, { 0x00, 0x00, 0x00, 0x01, 0xaa }, }, { { 0x79, 0x85, 0x62, 0xe0, 0x49, 0x85, 0x2f, 0x57, 0xdc, 0x8c, 0x34, 0x3b, 0xa1, 0x7f, 0x2c, 0xa1, 0xd9, 0x73, 0x94, 0xef, 0xc8, 0xad, 0xc4, 0x43, }, 5, { 0x00, 0x00, 0x00, 0x01, 0x55 }, }, { { 0x26, 0xdc, 0xe3, 0x34, 0xb5, 0x45, 0x29, 0x2f, 0x2f, 0xea, 0xb9, 0xa8, 0x70, 0x1a, 0x89, 0xa4, 0xb9, 0x9e, 0xb9, 0x94, 0x2c, 0xec, 0xd0, 0x16, }, 5, { 0x00, 0x00, 0x00, 0x01, 0xaa }, }, }; int i; for (i = 0; i < ASIZE(derive_tests); i++) { #define D (derive_tests[i]) krb5_keyblock key; krb5_data usage; unsigned char drData[KEYBYTES]; krb5_data dr; unsigned char dkData[KEYLENGTH]; krb5_keyblock dk; key.length = KEYLENGTH, key.contents = D.keydata; usage.length = D.usage_len, usage.data = D.usage; dr.length = KEYBYTES, dr.data = drData; dk.length = KEYLENGTH, dk.contents = dkData; printf ("key:\t"); printkey (&key); printf ("\n"); printf ("usage:\t"); printdata (&usage); printf ("\n"); DR (&dr, &key, &usage); printf ("DR:\t"); printdata (&dr); printf ("\n"); DK (&dk, &key, &usage); printf ("DK:\t"); printkey (&dk); printf ("\n\n"); } }