void TestApp::test_aes128() { Console::write_line(" Header: aes128_encrypt.h and aes128_decrypt.h"); Console::write_line(" Class: AES128_Encrypt and AES128_Decrypt"); // Test data from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf // and http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf test_aes128_helper( "2b7e151628aed2a6abf7158809cf4f3c", // KEY "000102030405060708090A0B0C0D0E0F", // IV "6bc1bee22e409f96e93d7e117393172a" // PLAINTEXT "ae2d8a571e03ac9c9eb76fac45af8e51" "30c81c46a35ce411e5fbc1191a0a52ef" "f69f2445df4f9b17ad2b417be66c3710", "7649abac8119b246cee98e9b12e9197d" // CIPHERTEXT "5086cb9b507219ee95db113a917678b2" "73bed6b8e3c1743b7116e69e22229516" "3ff1caa1681fac09120eca307586e1a7" ); const int test_data_length = 128; unsigned char test_data[test_data_length]; std::vector<unsigned char> key; std::vector<unsigned char> iv; convert_ascii("2B7E151628AED2A6ABF7158809CF4F3C", key); convert_ascii("000102030405060708090A0B0C0D0E0F", iv); for (int cnt=0; cnt<test_data_length; cnt++) { test_data[cnt] = (unsigned char) cnt; AES128_Encrypt aes128_encrypt; aes128_encrypt.set_iv(&iv[0]); aes128_encrypt.set_key(&key[0]); aes128_encrypt.add(test_data, cnt+1); aes128_encrypt.calculate(); AES128_Decrypt aes128_decrypt; aes128_decrypt.set_iv(&iv[0]); aes128_decrypt.set_key(&key[0]); DataBuffer buffer = aes128_encrypt.get_data(); aes128_decrypt.add(buffer.get_data(), buffer.get_size()); bool result = aes128_decrypt.calculate(); if (!result) fail(); DataBuffer buffer2 = aes128_decrypt.get_data(); if (buffer2.get_size() != cnt+1) fail(); unsigned char *data_ptr2 = (unsigned char *) buffer2.get_data(); if (memcmp(data_ptr2, test_data, cnt+1)) fail(); } }
void TestApp::test_aes192() { Console::write_line(" Header: aes192_encrypt.h and aes192_decrypt.h"); Console::write_line(" Class: AES192_Encrypt and AES192_Decrypt"); // Test data from http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf // and http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf test_aes192_helper( "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", // KEY "000102030405060708090A0B0C0D0E0F", // IV "6bc1bee22e409f96e93d7e117393172a" // PLAINTEXT "ae2d8a571e03ac9c9eb76fac45af8e51" "30c81c46a35ce411e5fbc1191a0a52ef" "f69f2445df4f9b17ad2b417be66c3710", "4f021db243bc633d7178183a9fa071e8" // CIPHERTEXT "b4d9ada9ad7dedf4e5e738763f69145a" "571b242012fb7ae07fa9baac3df102e0" "08b0e27988598881d920a9e64f5615cd" ); const int test_data_length = 192; unsigned char test_data[test_data_length]; std::vector<unsigned char> key; std::vector<unsigned char> iv; convert_ascii("8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B", key); convert_ascii("000102030405060708090A0B0C0D0E0F", iv); for (int cnt=0; cnt<test_data_length; cnt++) { test_data[cnt] = (unsigned char) cnt; AES192_Encrypt aes192_encrypt; aes192_encrypt.set_iv(&iv[0]); aes192_encrypt.set_key(&key[0]); aes192_encrypt.add(test_data, cnt+1); aes192_encrypt.calculate(); AES192_Decrypt aes192_decrypt; aes192_decrypt.set_iv(&iv[0]); aes192_decrypt.set_key(&key[0]); DataBuffer buffer = aes192_encrypt.get_data(); aes192_decrypt.add(buffer.get_data(), buffer.get_size()); bool result = aes192_decrypt.calculate(); if (!result) fail(); DataBuffer buffer2 = aes192_decrypt.get_data(); if (buffer2.get_size() != cnt+1) fail(); unsigned char *data_ptr2 = (unsigned char *) buffer2.get_data(); if (memcmp(data_ptr2, test_data, cnt+1)) fail(); } }
void TestApp::test_aes128_helper(const char *key_ptr, const char *iv_ptr, const char *plaintext_ptr, const char *ciphertext_ptr) { std::vector<unsigned char> key; std::vector<unsigned char> iv; std::vector<unsigned char> plaintext; std::vector<unsigned char> ciphertext; convert_ascii(key_ptr, key); convert_ascii(iv_ptr, iv); convert_ascii(plaintext_ptr, plaintext); convert_ascii(ciphertext_ptr, ciphertext); AES128_Encrypt aes128_encrypt; aes128_encrypt.set_padding(false); aes128_encrypt.set_iv(&iv[0]); aes128_encrypt.set_key(&key[0]); aes128_encrypt.add(&plaintext[0], plaintext.size()); aes128_encrypt.calculate(); DataBuffer buffer = aes128_encrypt.get_data(); if (buffer.get_size() != ciphertext.size()) fail(); unsigned char *data_ptr = (unsigned char *) buffer.get_data(); if (memcmp(data_ptr, &ciphertext[0], ciphertext.size())) fail(); AES128_Decrypt aes128_decrypt; aes128_decrypt.set_padding(false); aes128_decrypt.set_iv(&iv[0]); aes128_decrypt.set_key(&key[0]); aes128_decrypt.add(data_ptr, buffer.get_size()); bool result = aes128_decrypt.calculate(); if (!result) fail(); DataBuffer buffer2 = aes128_decrypt.get_data(); if (buffer2.get_size() != plaintext.size()) fail(); unsigned char *data_ptr2 = (unsigned char *) buffer2.get_data(); if (memcmp(data_ptr2, &plaintext[0], plaintext.size())) fail(); }
int cmd(string str){ int code; string tmp; string ret = ""; if(str && !code = atoi(str)){ write("That doesn't appear to be an integer."); return 1; } if(code) { ret = convert_ascii(code); write("The ASCII code "+code+" is: "+ret); return 1; } for(code = 33; code < 256; code++){ tmp = convert_ascii(code); if(sizeof(tmp)) ret += "The ASCII code "+code+" is: "+tmp+"\n"; } write(ret); return 1; }
static char *get_vptr_vector_val(Trptr t, vptr v) { char *ascii = NULL; if(v->time < LLDescriptor(0)) { ascii=strdup_2("X"); } else { ascii=convert_ascii(t,v); } if(!ascii) { ascii=strdup_2("X"); } format_value_string(ascii); return(ascii); }
/* * strace backward or forward..this was cut and * pasted from strace.c and special cased to handle * just a single trace. this might be relaxed later. */ static void edge_search_2(int direction, int is_last_iteration) { struct strace s_tmp; struct strace *s_head, *s; TimeType basetime, maxbase, sttim, fintim; Trptr t = find_first_highlighted_trace(); int totaltraces; #ifdef DEBUG_PRINTF int passcount; #endif int whichpass; TimeType middle=0, width; if(!t) return; memset(s_head = &s_tmp, 0, sizeof(struct strace)); s_head->trace = t; s_head->value = ST_ANY; s = s_head; while(t) { t = find_next_highlighted_trace(t); if(t) { s->next = wave_alloca(sizeof(struct strace)); memset(s = s->next, 0, sizeof(struct strace)); s->trace = t; s->value = ST_ANY; } } if(direction==STRACE_BACKWARD) /* backwards */ { if(GLOBALS->tims.marker<0) { basetime=MAX_HISTENT_TIME; } else { basetime=GLOBALS->tims.marker; } } else /* go forwards */ { if(GLOBALS->tims.marker<0) { basetime=GLOBALS->tims.first; } else { basetime=GLOBALS->tims.marker; } } sttim=GLOBALS->tims.first; fintim=GLOBALS->tims.last; for(whichpass=0;;whichpass++) { if(direction==STRACE_BACKWARD) /* backwards */ { maxbase=-1; s=s_head; while(s) { t=s->trace; GLOBALS->shift_timebase=t->shift; if(!(t->vector)) { hptr h; hptr *hp; UTimeType utt; TimeType tt; /* h= */ bsearch_node(t->n.nd, basetime - t->shift); /* scan-build */ hp=GLOBALS->max_compare_index; if((hp==&(t->n.nd->harray[1]))||(hp==&(t->n.nd->harray[0]))) return; if(basetime == ((*hp)->time+GLOBALS->shift_timebase)) hp--; h=*hp; s->his.h=h; utt=strace_adjust(h->time,GLOBALS->shift_timebase); tt=utt; if(tt > maxbase) maxbase=tt; } else { vptr v; vptr *vp; UTimeType utt; TimeType tt; /* v= */ bsearch_vector(t->n.vec, basetime - t->shift); /* scan-build */ vp=GLOBALS->vmax_compare_index; if((vp==&(t->n.vec->vectors[1]))||(vp==&(t->n.vec->vectors[0]))) return; if(basetime == ((*vp)->time+GLOBALS->shift_timebase)) vp--; v=*vp; s->his.v=v; utt=strace_adjust(v->time,GLOBALS->shift_timebase); tt=utt; if(tt > maxbase) maxbase=tt; } s=s->next; } } else /* go forward */ { maxbase=MAX_HISTENT_TIME; s=s_head; while(s) { t=s->trace; GLOBALS->shift_timebase=t->shift; if(!(t->vector)) { hptr h; UTimeType utt; TimeType tt; h=bsearch_node(t->n.nd, basetime - t->shift); while(h->next && h->time==h->next->time) h=h->next; if((whichpass)||(GLOBALS->tims.marker>=0)) h=h->next; if(!h) return; s->his.h=h; utt=strace_adjust(h->time,GLOBALS->shift_timebase); tt=utt; if(tt < maxbase) maxbase=tt; } else { vptr v; UTimeType utt; TimeType tt; v=bsearch_vector(t->n.vec, basetime - t->shift); while(v->next && v->time==v->next->time) v=v->next; if((whichpass)||(GLOBALS->tims.marker>=0)) v=v->next; if(!v) return; s->his.v=v; utt=strace_adjust(v->time,GLOBALS->shift_timebase); tt=utt; if(tt < maxbase) maxbase=tt; } s=s->next; } } s=s_head; totaltraces=0; /* increment when not don't care */ while(s) { /* commented out, maybe will have possible future expansion later, * this was cut and pasted from strace.c */ #if 0 char str[2]; #endif t=s->trace; s->search_result=0; /* explicitly must set this */ GLOBALS->shift_timebase=t->shift; if((!t->vector)&&(!(t->n.nd->extvals))) { if(strace_adjust(s->his.h->time,GLOBALS->shift_timebase)!=maxbase) { s->his.h=bsearch_node(t->n.nd, maxbase - t->shift); while(s->his.h->next && s->his.h->time==s->his.h->next->time) s->his.h=s->his.h->next; } /* commented out, maybe will have possible future expansion later, * this was cut and pasted from strace.c */ #if 0 if(t->flags&TR_INVERT) { str[0]=AN_STR_INV[s->his.h->v.h_val]; } else { str[0]=AN_STR[s->his.h->v.h_val]; } str[1]=0x00; #endif switch(s->value) { case ST_ANY: totaltraces++; s->search_result=1; break; /* commented out, maybe will have possible future expansion later, * this was cut and pasted from strace.c */ #if 0 case ST_DC: break; case ST_HIGH: totaltraces++; if((str[0]=='1')||(str[0]=='H')) s->search_result=1; break; case ST_RISE: if((str[0]=='1')||(str[0]=='H')) s->search_result=1; totaltraces++; break; case ST_LOW: totaltraces++; if((str[0]=='0')||(str[0]=='L')) s->search_result=1; break; case ST_FALL: totaltraces++; if((str[0]=='0')||(str[0]=='L')) s->search_result=1; break; case ST_MID: totaltraces++; if(str[0]=='Z') s->search_result=1; break; case ST_X: totaltraces++; if(str[0]=='X') s->search_result=1; break; case ST_STRING: totaltraces++; if(s->string) if(strstr_i(s->string,str)) s->search_result=1; break; #endif default: fprintf(stderr, "Internal error: st_type of %d\n",s->value); exit(255); } } else { char *chval, *chval2; char ch; if(t->vector) { if(strace_adjust(s->his.v->time,GLOBALS->shift_timebase)!=maxbase) { s->his.v=bsearch_vector(t->n.vec, maxbase - t->shift); while(s->his.v->next && s->his.v->time==s->his.v->next->time) s->his.v=s->his.v->next; } chval=convert_ascii(t,s->his.v); } else { if(strace_adjust(s->his.h->time,GLOBALS->shift_timebase)!=maxbase) { s->his.h=bsearch_node(t->n.nd, maxbase - t->shift); while(s->his.h->next && s->his.h->time==s->his.h->next->time) s->his.h=s->his.h->next; } if(s->his.h->flags&HIST_REAL) { if(!(s->his.h->flags&HIST_STRING)) { #ifdef WAVE_HAS_H_DOUBLE chval=convert_ascii_real(t, &s->his.h->v.h_double); #else chval=convert_ascii_real(t, (double *)s->his.h->v.h_vector); #endif } else { chval=convert_ascii_string((char *)s->his.h->v.h_vector); chval2=chval; while((ch=*chval2)) /* toupper() the string */ { if((ch>='a')&&(ch<='z')) { *chval2= ch-('a'-'A'); } chval2++; } } } else { chval=convert_ascii_vec(t,s->his.h->v.h_vector); } } switch(s->value) { case ST_ANY: totaltraces++; s->search_result=1; break; /* commented out, maybe will have possible future expansion later, * this was cut and pasted from strace.c */ #if 0 case ST_DC: break; case ST_RISE: case ST_FALL: totaltraces++; break; case ST_HIGH: totaltraces++; if((chval2=chval)) while((ch=*(chval2++))) { if(((ch>='1')&&(ch<='9'))||(ch=='h')||(ch=='H')||((ch>='A')&&(ch<='F'))) { s->search_result=1; break; } } break; case ST_LOW: totaltraces++; if((chval2=chval)) { s->search_result=1; while((ch=*(chval2++))) { if((ch!='0')&&(ch!='l')&&(ch!='L')) { s->search_result=0; break; } } } break; case ST_MID: totaltraces++; if((chval2=chval)) { s->search_result=1; while((ch=*(chval2++))) { if((ch!='z')&&(ch!='Z')) { s->search_result=0; break; } } } break; case ST_X: totaltraces++; if((chval2=chval)) { s->search_result=1; while((ch=*(chval2++))) { if((ch!='X')&&(ch!='W')&&(ch!='x')&&(ch!='w')) { s->search_result=0; break; } } } break; case ST_STRING: totaltraces++; if(s->string) if(strstr_i(chval, s->string)) s->search_result=1; break; #endif default: fprintf(stderr, "Internal error: st_type of %d\n",s->value); exit(255); } free_2(chval); } s=s->next; } if((maxbase<sttim)||(maxbase>fintim)) return; #ifdef DEBUG_PRINTF DEBUG(printf("Maxbase: "TTFormat", total traces: %d\n",maxbase, totaltraces)); s=s_head; passcount=0; while(s) { DEBUG(printf("\tPass: %d, Name: %s\n",s->search_result, s->trace->name)); if(s->search_result) passcount++; s=s->next; } #endif if(totaltraces) { break; } basetime=maxbase; } GLOBALS->tims.marker=maxbase; if(is_last_iteration) { update_markertime(GLOBALS->tims.marker); width=(TimeType)(((gdouble)GLOBALS->wavewidth)*GLOBALS->nspx); if((GLOBALS->tims.marker<GLOBALS->tims.start)||(GLOBALS->tims.marker>=GLOBALS->tims.start+width)) { if((GLOBALS->tims.marker<0)||(GLOBALS->tims.marker<GLOBALS->tims.first)||(GLOBALS->tims.marker>GLOBALS->tims.last)) { if(GLOBALS->tims.end>GLOBALS->tims.last) GLOBALS->tims.end=GLOBALS->tims.last; middle=(GLOBALS->tims.start/2)+(GLOBALS->tims.end/2); if((GLOBALS->tims.start&1)&&(GLOBALS->tims.end&1)) middle++; } else { middle=GLOBALS->tims.marker; } GLOBALS->tims.start=time_trunc(middle-(width/2)); if(GLOBALS->tims.start+width>GLOBALS->tims.last) GLOBALS->tims.start=GLOBALS->tims.last-width; if(GLOBALS->tims.start<GLOBALS->tims.first) GLOBALS->tims.start=GLOBALS->tims.first; GTK_ADJUSTMENT(GLOBALS->wave_hslider)->value=GLOBALS->tims.timecache=GLOBALS->tims.start; } MaxSignalLength(); signalarea_configure_event(GLOBALS->signalarea, NULL); wavearea_configure_event(GLOBALS->wavearea, NULL); } }