/* * Wrapper for x509 hashes. */ static void x509_hash( const unsigned char *in, size_t len, int alg, unsigned char *out ) { switch( alg ) { #if defined(POLARSSL_MD2_C) case SIG_RSA_MD2 : md2( in, len, out ); break; #endif #if defined(POLARSSL_MD4_C) case SIG_RSA_MD4 : md4( in, len, out ); break; #endif #if defined(POLARSSL_MD5_C) case SIG_RSA_MD5 : md5( in, len, out ); break; #endif #if defined(POLARSSL_SHA1_C) case SIG_RSA_SHA1 : sha1( in, len, out ); break; #endif #if defined(POLARSSL_SHA2_C) case SIG_RSA_SHA224 : sha2( in, len, out, 1 ); break; case SIG_RSA_SHA256 : sha2( in, len, out, 0 ); break; #endif #if defined(POLARSSL_SHA4_C) case SIG_RSA_SHA384 : sha4( in, len, out, 1 ); break; case SIG_RSA_SHA512 : sha4( in, len, out, 0 ); break; #endif default: memset( out, '\xFF', 64 ); break; } }
void MainWindow::HandleTextChanged() { QString original = ui->plainTextEditOriginal->toPlainText(); QString convertFrom = ""; QString convertTo = ""; QCryptographicHash sha1(QCryptographicHash::Sha1); QCryptographicHash md4(QCryptographicHash::Md4); QCryptographicHash md5(QCryptographicHash::Md5); QScriptEngine jsengine; sha1.addData(original.toAscii()); md4.addData(original.toAscii()); md5.addData(original.toAscii()); convertTo.append(QString("SHA1:\n%0\n\n").arg(QString(sha1.result().toHex()))); convertTo.append(QString("MD4:\n%0\n\n").arg(QString(md4.result().toHex()))); convertTo.append(QString("MD5:\n%0\n\n").arg(QString(md5.result().toHex()))); convertTo.append(QString("Base64:\n%0\n\n").arg(QString(original.toAscii().toBase64()))); convertTo.append(QString("Hex:\n%0\n\n").arg(QString(original.toAscii().toHex()))); convertTo.append(QString("Percent Encoding:\n%0\n\n").arg(QString(original.toAscii().toPercentEncoding()))); convertFrom.append(QString("Base64:\n%0\n\n").arg(QString(QByteArray::fromBase64(original.toAscii())))); convertFrom.append(QString("Hex:\n%0\n\n").arg(QString(QByteArray::fromHex(original.toAscii())))); convertFrom.append(QString("Percent Encoding:\n%0\n\n").arg(QString(QByteArray::fromPercentEncoding(original.toAscii())))); convertFrom.append(QString("JavaScript:\n%0\n\n").arg(jsengine.evaluate(original).toString())); ui->plainTextEditConvertTo->setPlainText(convertTo); ui->plainTextEditConvertFrom->setPlainText(convertFrom); }
int main(void) { long long int time=0; Led0 led;Blink blink0(led);blink0.setup();blink0.time(100); A0 a0;Blink blink1(a0);blink1.setup();blink1.time(100); Serial0 serial;serial.setup(115200); Serial1 serial1; Enc0 l;Enc1 r;Enc2 b; RobotCenter center(l,r,b);center.setup(); Can0 can; DualShock ps3(serial1); ps3.setStickTolerance(0.1); //DualShock ps3(serial1);ps3.setup(); /*Cw4 cw4;Ccw4 ccw4;Pwm4 pwm4;Md md4(cw4,ccw4,pwm4); Cw5 cw5;Ccw5 ccw5;Pwm5 pwm5;Md md5(cw5,ccw5,pwm5); Cw6 cw6;Ccw6 ccw6;Pwm6 pwm6;Md md6(cw6,ccw6,pwm6); Cw7 cw7;Ccw7 ccw7;Pwm7 pwm7;Md md7(cw7,ccw7,pwm7);*/ CW0 cw4;CCW0 ccw4;Pwm0 pwm4;Md md4(cw4,ccw4,pwm4); CW1 cw5;CCW1 ccw5;Pwm1 pwm5;Md md5(cw5,ccw5,pwm5); CW2 cw6;CCW2 ccw6;Pwm2 pwm6;Md md6(cw6,ccw6,pwm6); CW3 cw7;CCW3 ccw7;Pwm3 pwm7;Md md7(cw7,ccw7,pwm7); Move move(md4,md5,md6,md7,center,ps3);move.setup(); Debug debug(serial,center,ps3);debug.setup(); while(1){ blink0.cycle(); center.cycle(); ps3.cycle(); //move.manualModeCycle(); debug.cycle(); if(millis()-time>=100){ time=millis(); /*serial.printf("lx:%.4f",ps3.lx()); serial.printf("ly:%.4f",ps3.ly()); serial.printf("rx:%.4f",ps3.rx()); serial.printf("ry:%.4f",ps3.ry()); serial.printf("u:%.4f",ps3.up()); serial.printf("r:%.4f",ps3.right()); serial.printf("d:%.4f",ps3.down()); serial.printf("l:%.4f",ps3.left()); serial.printf("tri:%.4f",ps3.triangle()); serial.printf("cir:%.4f",ps3.circle()); serial.printf("cro:%.4f",ps3.cross()); serial.printf("squ:%.4f",ps3.square()); serial.printf("l1:%.4f",ps3.l1()); serial.printf("l2:%.4f",ps3.l2()); serial.printf("r1:%.4f",ps3.r1()); serial.printf("r2:%.4f",ps3.r2()); serial.printf("start:%.4f",ps3.start()); serial.printf("select:%.4f",ps3.select()); serial.printf("dis:%d\n",ps3.disconnect());*/ //serial.printf("ang,% .4f, x,% .4f, y,% .4f\n",rtod(center.getAngle()),center.x(),center.y()); } } return 0; }
static void md4tests(void) { md4("", "31d6cfe0d16ae931b73c59d7e0c089c0"); md4("a", "bde52cb31de33e46245e05fbdbd6fb24"); md4("abc", "a448017aaf21d8525fc10ae87aa6729d"); md4("message digest", "d9130a8164549fe818874806e1c7014b"); md4("abcdefghijklmnopqrstuvwxyz", "d79e1c308aa5bbcdeea8ed63df412da9"); md4("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "043f8582f241db351ce627e153e7f0e4"); md4("12345678901234567890123456789012345678901234567890123456789012345678901234567890", "e33b4ddc9c38f2199c3e7b164fcc0536"); }
void testMediaDescriptor_TypeAndDirectionality() { const char *sdp = "v=0\r\n" "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\r\n" "s=SDP Seminar\r\n" "i=A Seminar on the session description protocol\r\n" "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\r\n" "[email protected] (Mark Handley)\r\n" "c=IN IP4 224.2.17.12/127\r\n" "t=2873397496 2873404696\r\n" "m=audio 49170 RTP/AVP 0\r\n" // media description 0 "c=IN IP4 224.2.17.12/127\r\n" "a=recvonly\r\n" "m=video 51372 RTP/AVP 31\r\n" // media description 1 "a=inactive\r\n" "m=application 32416 udp wb\r\n" // media description 2 "a=sendonly\r\n" "m=audio 55554 RTP/AVP 0\r\n" // media description 3 "c=IN IP4 224.2.17.12/127\r\n" "a=sendrecv\r\n" "m=audio 55560 RTP/AVP 0\r\n" // media description 4 ; SdpBody body(sdp); MediaDescriptor md0( body, 0, CALLER ); MediaDescriptor md1( body, 1, CALLER ); MediaDescriptor md2( body, 2, CALLER ); MediaDescriptor md3( body, 3, CALLER ); MediaDescriptor md4( body, 4, CALLER ); CPPUNIT_ASSERT( md0.getType() == "audio" ); CPPUNIT_ASSERT( md0.getDirectionality() == RECV_ONLY ); CPPUNIT_ASSERT( md0.getDirectionalityOverride() == NOT_A_DIRECTION ); md0.setDirectionalityOverride( INACTIVE ); CPPUNIT_ASSERT( md0.getDirectionalityOverride() == INACTIVE ); CPPUNIT_ASSERT( md1.getType() == "video" ); CPPUNIT_ASSERT( md1.getDirectionality() == INACTIVE ); CPPUNIT_ASSERT( md2.getType() == "application" ); CPPUNIT_ASSERT( md2.getDirectionality() == SEND_ONLY ); CPPUNIT_ASSERT( md3.getType() == "audio" ); CPPUNIT_ASSERT( md3.getDirectionality() == SEND_RECV ); CPPUNIT_ASSERT( md4.getType() == "audio" ); CPPUNIT_ASSERT( md4.getDirectionality() == SEND_RECV ); }
void NtPasswordHash(char *secret, int secret_len, unsigned char *hash) { int i; u_char unicodePassword[MAX_NT_PASSWORD * 2]; /* Initialize the Unicode version of the secret (== password). */ /* This implicitly supports 8-bit ISO8859/1 characters. */ BZERO(unicodePassword, sizeof(unicodePassword)); for (i = 0; i < secret_len; i++) unicodePassword[i * 2] = (u_char)secret[i]; /* Unicode is 2 bytes per char */ md4(unicodePassword, secret_len * 2, hash); }
void nthash(uchar hash[MShashlen], char *passwd) { uchar buf[512]; int i; for (i = 0; *passwd && i + 1 < sizeof(buf);) { Rune r; passwd += chartorune(&r, passwd); buf[i++] = r; buf[i++] = r >> 8; } memset(hash, 0, 16); md4(buf, i, hash, 0); }
int md(const char *fpt, unsigned long *IH) { unsigned long c = 0x00000000UL; unsigned long e = 0x00000000UL; unsigned long i = 0x00000000UL; union { unsigned long long qword ; unsigned long dword[0x02]; } byte; FILE *fp = NULL ; union { unsigned long dword[0x10]; unsigned short word[0x20]; unsigned char byte[0x40]; } M; if(strcmp(fpt, "-")) { if(checkf(fpt) == 1) return 1; fp = fopen(fpt, "rb"); } else fp = stdin; if(fpt && fp) { byte.qword = 0x0000000000000000ULL; c = 0x00000001UL; for(e=0; e<0x04; e++) IH[e] = 0x00000000UL; /* erase first */ while (!feof(fp)) { for(e=0; e<0x10; e++) M.dword[e] = 0x00000000UL; /* erase first */ if((i = fread(&M, 1, 0x40, fp)) == 0x40) { { md4(M.dword, IH, c); c = 0; } byte.qword = byte.qword + 0x40; } else { if (i == 0) { byte.qword = (byte.qword + i) << 3; M.dword[0x0] = 0x00000080UL; M.dword[0xe] = (byte.dword[0x0]); M.dword[0xf] = (byte.dword[0x1]); md4(M.dword, IH, c); } else { M.byte [ i ] = 0x80; if(i < 0x38) { byte.qword = (byte.qword + i) << 3; M.dword[0xe] = (byte.dword[0x0]); M.dword[0xf] = (byte.dword[0x1]); md4(M.dword, IH, c); } else { M.dword[0xe] = (M.dword[0xe]); M.dword[0xf] = (M.dword[0xf]); { md4(M.dword, IH, c); c = 0;} for(e=0; e<0x10; e++) M.dword[e] = 0x00000000UL; /* erase first */ byte.qword = (byte.qword + i) << 3; M.dword[0xe] = (byte.dword[0x0]); M.dword[0xf] = (byte.dword[0x1]); md4(M.dword, IH, c); } } } } fclose(fp); } else { return 1; } for(e=0; e<0x04; e++) IH[e] = swapul(IH[e]); return 0; }
int main( int argc, char *argv[] ) { int keysize; unsigned long i, j, tsc; unsigned char tmp[64]; #if defined(POLARSSL_ARC4_C) arc4_context arc4; #endif #if defined(POLARSSL_DES_C) des3_context des3; des_context des; #endif #if defined(POLARSSL_AES_C) aes_context aes; #endif #if defined(POLARSSL_CAMELLIA_C) camellia_context camellia; #endif #if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \ defined(POLARSSL_GENPRIME) rsa_context rsa; #endif #if defined(POLARSSL_HAVEGE_C) havege_state hs; #endif #if defined(POLARSSL_CTR_DRBG_C) ctr_drbg_context ctr_drbg; #endif ((void) argc); ((void) argv); memset( buf, 0xAA, sizeof( buf ) ); printf( "\n" ); #if defined(POLARSSL_MD4_C) printf( HEADER_FORMAT, "MD4" ); fflush( stdout ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) md4( buf, BUFSIZE, tmp ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) md4( buf, BUFSIZE, tmp ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_MD5_C) printf( HEADER_FORMAT, "MD5" ); fflush( stdout ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) md5( buf, BUFSIZE, tmp ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) md5( buf, BUFSIZE, tmp ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_SHA1_C) printf( HEADER_FORMAT, "SHA-1" ); fflush( stdout ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) sha1( buf, BUFSIZE, tmp ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) sha1( buf, BUFSIZE, tmp ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_SHA2_C) printf( HEADER_FORMAT, "SHA-256" ); fflush( stdout ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) sha2( buf, BUFSIZE, tmp, 0 ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) sha2( buf, BUFSIZE, tmp, 0 ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_SHA4_C) printf( HEADER_FORMAT, "SHA-512" ); fflush( stdout ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) sha4( buf, BUFSIZE, tmp, 0 ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) sha4( buf, BUFSIZE, tmp, 0 ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_ARC4_C) printf( HEADER_FORMAT, "ARC4" ); fflush( stdout ); arc4_setup( &arc4, tmp, 32 ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) arc4_crypt( &arc4, BUFSIZE, buf, buf ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) arc4_crypt( &arc4, BUFSIZE, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_DES_C) printf( HEADER_FORMAT, "3DES" ); fflush( stdout ); des3_set3key_enc( &des3, tmp ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); printf( HEADER_FORMAT, "DES" ); fflush( stdout ); des_setkey_enc( &des, tmp ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_AES_C) for( keysize = 128; keysize <= 256; keysize += 64 ) { printf( " AES-%d : ", keysize ); fflush( stdout ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); aes_setkey_enc( &aes, tmp, keysize ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 4096; j++ ) aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); } #endif #if defined(POLARSSL_CAMELLIA_C) for( keysize = 128; keysize <= 256; keysize += 64 ) { printf( " CAMELLIA-%d : ", keysize ); fflush( stdout ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); camellia_setkey_enc( &camellia, tmp, keysize ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 4096; j++ ) camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); } #endif #if defined(POLARSSL_HAVEGE_C) printf( HEADER_FORMAT, "HAVEGE" ); fflush( stdout ); havege_init( &hs ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) havege_random( &hs, buf, BUFSIZE ); tsc = hardclock(); for( j = 1; j < 1024; j++ ) havege_random( &hs, buf, BUFSIZE ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_CTR_DRBG_C) printf( HEADER_FORMAT, "CTR_DRBG (NOPR)" ); fflush( stdout ); if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) exit(1); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1); tsc = hardclock(); for( j = 1; j < 1024; j++ ) if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); printf( HEADER_FORMAT, "CTR_DRBG (PR)" ); fflush( stdout ); if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) exit(1); ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON ); set_alarm( 1 ); for( i = 1; ! alarmed; i++ ) if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1); tsc = hardclock(); for( j = 1; j < 1024; j++ ) if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \ defined(POLARSSL_GENPRIME) rsa_init( &rsa, RSA_PKCS_V15, 0 ); rsa_gen_key( &rsa, myrand, NULL, 1024, 65537 ); printf( HEADER_FORMAT, "RSA-1024" ); fflush( stdout ); set_alarm( 3 ); for( i = 1; ! alarmed; i++ ) { buf[0] = 0; rsa_public( &rsa, buf, buf ); } printf( "%9lu public/s\n", i / 3 ); printf( HEADER_FORMAT, "RSA-1024" ); fflush( stdout ); set_alarm( 3 ); for( i = 1; ! alarmed; i++ ) { buf[0] = 0; rsa_private( &rsa, buf, buf ); } printf( "%9lu private/s\n", i / 3 ); rsa_free( &rsa ); rsa_init( &rsa, RSA_PKCS_V15, 0 ); rsa_gen_key( &rsa, myrand, NULL, 2048, 65537 ); printf( HEADER_FORMAT, "RSA-2048" ); fflush( stdout ); set_alarm( 3 ); for( i = 1; ! alarmed; i++ ) { buf[0] = 0; rsa_public( &rsa, buf, buf ); } printf( "%9lu public/s\n", i / 3 ); printf( HEADER_FORMAT, "RSA-2048" ); fflush( stdout ); set_alarm( 3 ); for( i = 1; ! alarmed; i++ ) { buf[0] = 0; rsa_private( &rsa, buf, buf ); } printf( "%9lu private/s\n", i / 3 ); rsa_free( &rsa ); rsa_init( &rsa, RSA_PKCS_V15, 0 ); rsa_gen_key( &rsa, myrand, NULL, 4096, 65537 ); printf( HEADER_FORMAT, "RSA-4096" ); fflush( stdout ); set_alarm( 3 ); for( i = 1; ! alarmed; i++ ) { buf[0] = 0; rsa_public( &rsa, buf, buf ); } printf( "%9lu public/s\n", i / 3 ); printf( HEADER_FORMAT, "RSA-4096" ); fflush( stdout ); set_alarm( 3 ); for( i = 1; ! alarmed; i++ ) { buf[0] = 0; rsa_private( &rsa, buf, buf ); } printf( "%9lu private/s\n", i / 3 ); rsa_free( &rsa ); #endif printf( "\n" ); #if defined(_WIN32) printf( " Press Enter to exit this program.\n" ); fflush( stdout ); getchar(); #endif return( 0 ); }
int main( int argc, char *argv[] ) { int keysize, i; unsigned char tmp[200]; char title[TITLE_LEN]; todo_list todo; if( argc == 1 ) memset( &todo, 1, sizeof( todo ) ); else { memset( &todo, 0, sizeof( todo ) ); for( i = 1; i < argc; i++ ) { if( strcmp( argv[i], "md4" ) == 0 ) todo.md4 = 1; else if( strcmp( argv[i], "md5" ) == 0 ) todo.md5 = 1; else if( strcmp( argv[i], "ripemd160" ) == 0 ) todo.ripemd160 = 1; else if( strcmp( argv[i], "sha1" ) == 0 ) todo.sha1 = 1; else if( strcmp( argv[i], "sha256" ) == 0 ) todo.sha256 = 1; else if( strcmp( argv[i], "sha512" ) == 0 ) todo.sha512 = 1; else if( strcmp( argv[i], "arc4" ) == 0 ) todo.arc4 = 1; else if( strcmp( argv[i], "des3" ) == 0 ) todo.des3 = 1; else if( strcmp( argv[i], "des" ) == 0 ) todo.des = 1; else if( strcmp( argv[i], "aes_cbc" ) == 0 ) todo.aes_cbc = 1; else if( strcmp( argv[i], "aes_gcm" ) == 0 ) todo.aes_gcm = 1; else if( strcmp( argv[i], "camellia" ) == 0 ) todo.camellia = 1; else if( strcmp( argv[i], "blowfish" ) == 0 ) todo.blowfish = 1; else if( strcmp( argv[i], "havege" ) == 0 ) todo.havege = 1; else if( strcmp( argv[i], "ctr_drbg" ) == 0 ) todo.ctr_drbg = 1; else if( strcmp( argv[i], "hmac_drbg" ) == 0 ) todo.hmac_drbg = 1; else if( strcmp( argv[i], "rsa" ) == 0 ) todo.rsa = 1; else if( strcmp( argv[i], "dhm" ) == 0 ) todo.dhm = 1; else if( strcmp( argv[i], "ecdsa" ) == 0 ) todo.ecdsa = 1; else if( strcmp( argv[i], "ecdh" ) == 0 ) todo.ecdh = 1; else { printf( "Unrecognized option: %s\n", argv[i] ); printf( "Available options:" OPTIONS ); } } } printf( "\n" ); memset( buf, 0xAA, sizeof( buf ) ); #if defined(POLARSSL_MD4_C) if( todo.md4 ) TIME_AND_TSC( "MD4", md4( buf, BUFSIZE, tmp ) ); #endif #if defined(POLARSSL_MD5_C) if( todo.md5 ) TIME_AND_TSC( "MD5", md5( buf, BUFSIZE, tmp ) ); #endif #if defined(POLARSSL_RIPEMD160_C) if( todo.ripemd160 ) TIME_AND_TSC( "RIPEMD160", ripemd160( buf, BUFSIZE, tmp ) ); #endif #if defined(POLARSSL_SHA1_C) if( todo.sha1 ) TIME_AND_TSC( "SHA-1", sha1( buf, BUFSIZE, tmp ) ); #endif #if defined(POLARSSL_SHA256_C) if( todo.sha256 ) TIME_AND_TSC( "SHA-256", sha256( buf, BUFSIZE, tmp, 0 ) ); #endif #if defined(POLARSSL_SHA512_C) if( todo.sha512 ) TIME_AND_TSC( "SHA-512", sha512( buf, BUFSIZE, tmp, 0 ) ); #endif #if defined(POLARSSL_ARC4_C) if( todo.arc4 ) { arc4_context arc4; arc4_setup( &arc4, tmp, 32 ); TIME_AND_TSC( "ARC4", arc4_crypt( &arc4, BUFSIZE, buf, buf ) ); } #endif #if defined(POLARSSL_DES_C) && defined(POLARSSL_CIPHER_MODE_CBC) if( todo.des3 ) { des3_context des3; des3_set3key_enc( &des3, tmp ); TIME_AND_TSC( "3DES", des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } if( todo.des ) { des_context des; des_setkey_enc( &des, tmp ); TIME_AND_TSC( "DES", des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } #endif #if defined(POLARSSL_AES_C) #if defined(POLARSSL_CIPHER_MODE_CBC) if( todo.aes_cbc ) { aes_context aes; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "AES-CBC-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); aes_setkey_enc( &aes, tmp, keysize ); TIME_AND_TSC( title, aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } } #endif #if defined(POLARSSL_GCM_C) if( todo.aes_gcm ) { gcm_context gcm; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "AES-GCM-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); gcm_init( &gcm, POLARSSL_CIPHER_ID_AES, tmp, keysize ); TIME_AND_TSC( title, gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp ) ); gcm_free( &gcm ); } } #endif #endif #if defined(POLARSSL_CAMELLIA_C) && defined(POLARSSL_CIPHER_MODE_CBC) if( todo.camellia ) { camellia_context camellia; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "CAMELLIA-CBC-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); camellia_setkey_enc( &camellia, tmp, keysize ); TIME_AND_TSC( title, camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } } #endif #if defined(POLARSSL_BLOWFISH_C) && defined(POLARSSL_CIPHER_MODE_CBC) if( todo.blowfish ) { blowfish_context blowfish; for( keysize = 128; keysize <= 256; keysize += 64 ) { snprintf( title, sizeof( title ), "BLOWFISH-CBC-%d", keysize ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); blowfish_setkey( &blowfish, tmp, keysize ); TIME_AND_TSC( title, blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf ) ); } } #endif #if defined(POLARSSL_HAVEGE_C) if( todo.havege ) { havege_state hs; havege_init( &hs ); TIME_AND_TSC( "HAVEGE", havege_random( &hs, buf, BUFSIZE ) ); } #endif #if defined(POLARSSL_CTR_DRBG_C) if( todo.ctr_drbg ) { ctr_drbg_context ctr_drbg; if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) exit(1); TIME_AND_TSC( "CTR_DRBG (NOPR)", if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1) ); if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 ) exit(1); ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON ); TIME_AND_TSC( "CTR_DRBG (PR)", if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 ) exit(1) ); }
static inline void md4s(md4_ctx_t *ctx, char *str) { md4(ctx, str, strlen(str)); }
// ***************************************************************************** // Main int main(int argc, char* const argv[]) { try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } std::string file(argv[1]); std::cout <<"----- One IFD0 tag\n"; Exiv2::ExifData ed1; Exiv2::Exifdatum md1(Exiv2::ExifKey("Exif.Image.Model")); md1.setValue("Test 1"); ed1.add(md1); write(file, ed1); print(file); std::cout <<"\n----- One Exif tag\n"; Exiv2::ExifData ed2; Exiv2::Exifdatum md2(Exiv2::ExifKey("Exif.Photo.DateTimeOriginal")); md2.setValue("Test 2"); ed2.add(md2); write(file, ed2); print(file); // Todo: One Makernote tag for each Makernote std::cout <<"\n----- One IOP tag\n"; Exiv2::ExifData ed3; Exiv2::Exifdatum md3(Exiv2::ExifKey("Exif.Iop.InteroperabilityVersion")); md3.setValue("Test 3"); ed3.add(md3); write(file, ed3); print(file); std::cout <<"\n----- One GPS tag\n"; Exiv2::ExifData ed4; Exiv2::Exifdatum md4(Exiv2::ExifKey("Exif.GPSInfo.GPSVersionID")); md4.setValue("Test 4"); ed4.add(md4); write(file, ed4); print(file); // Todo: Fix this std::cout <<"\n----- One IFD1 tag\n"; Exiv2::ExifData ed5; Exiv2::Exifdatum md5(Exiv2::ExifKey("Exif.Thumbnail.Artist")); md5.setValue("Test 5"); ed5.add(md5); Exiv2::Exifdatum md6(Exiv2::ExifKey("Exif.Image.Model")); md6.setValue("Test 5 (Fix me!)"); ed5.add(md6); write(file, ed5); print(file); return 0; } catch (Exiv2::Error& e) { std::cout << "Caught Exiv2 exception '" << e << "'\n"; return -1; } }
int main(void) { int keysize; unsigned long i, j, tsc; unsigned char tmp[32]; #if defined(TROPICSSL_ARC4_C) arc4_context arc4; #endif #if defined(TROPICSSL_DES_C) des3_context des3; des_context des; #endif #if defined(TROPICSSL_AES_C) aes_context aes; #endif #if defined(TROPICSSL_CAMELLIA_C) camellia_context camellia; #endif #if defined(TROPICSSL_RSA_C) rsa_context rsa; #endif memset(buf, 0xAA, sizeof(buf)); printf("\n"); #if defined(TROPICSSL_MD4_C) printf(" MD4 : "); fflush(stdout); set_alarm(1); for (i = 1; !alarmed; i++) md4(buf, BUFSIZE, tmp); tsc = hardclock(); for (j = 0; j < 1024; j++) md4(buf, BUFSIZE, tmp); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); #endif #if defined(TROPICSSL_MD5_C) printf(" MD5 : "); fflush(stdout); set_alarm(1); for (i = 1; !alarmed; i++) md5(buf, BUFSIZE, tmp); tsc = hardclock(); for (j = 0; j < 1024; j++) md5(buf, BUFSIZE, tmp); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); #endif #if defined(TROPICSSL_SHA1_C) printf(" SHA-1 : "); fflush(stdout); set_alarm(1); for (i = 1; !alarmed; i++) sha1(buf, BUFSIZE, tmp); tsc = hardclock(); for (j = 0; j < 1024; j++) sha1(buf, BUFSIZE, tmp); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); #endif #if defined(TROPICSSL_SHA2_C) printf(" SHA-256 : "); fflush(stdout); set_alarm(1); for (i = 1; !alarmed; i++) sha2(buf, BUFSIZE, tmp, 0); tsc = hardclock(); for (j = 0; j < 1024; j++) sha2(buf, BUFSIZE, tmp, 0); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); #endif #if defined(TROPICSSL_ARC4_C) printf(" ARC4 : "); fflush(stdout); arc4_setup(&arc4, tmp, 32); set_alarm(1); for (i = 1; !alarmed; i++) arc4_crypt(&arc4, buf, BUFSIZE); tsc = hardclock(); for (j = 0; j < 1024; j++) arc4_crypt(&arc4, buf, BUFSIZE); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); #endif #if defined(TROPICSSL_DES_C) printf(" 3DES : "); fflush(stdout); des3_set3key_enc(&des3, tmp); set_alarm(1); for (i = 1; !alarmed; i++) des3_crypt_cbc(&des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf); tsc = hardclock(); for (j = 0; j < 1024; j++) des3_crypt_cbc(&des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); printf(" DES : "); fflush(stdout); des_setkey_enc(&des, tmp); set_alarm(1); for (i = 1; !alarmed; i++) des_crypt_cbc(&des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf); tsc = hardclock(); for (j = 0; j < 1024; j++) des_crypt_cbc(&des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); #endif #if defined(TROPICSSL_AES_C) for (keysize = 128; keysize <= 256; keysize += 64) { printf(" AES-%d : ", keysize); fflush(stdout); memset(buf, 0, sizeof(buf)); memset(tmp, 0, sizeof(tmp)); aes_setkey_enc(&aes, tmp, keysize); set_alarm(1); for (i = 1; !alarmed; i++) aes_crypt_cbc(&aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf); tsc = hardclock(); for (j = 0; j < 4096; j++) aes_crypt_cbc(&aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); } #endif #if defined(TROPICSSL_CAMELLIA_C) for (keysize = 128; keysize <= 256; keysize += 64) { printf(" CAMELLIA-%d : ", keysize); fflush(stdout); memset(buf, 0, sizeof(buf)); memset(tmp, 0, sizeof(tmp)); camellia_setkey_enc(&camellia, tmp, keysize); set_alarm(1); for (i = 1; !alarmed; i++) camellia_crypt_cbc(&camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf); tsc = hardclock(); for (j = 0; j < 4096; j++) camellia_crypt_cbc(&camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf); printf("%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, (hardclock() - tsc) / (j * BUFSIZE)); } #endif #if defined(TROPICSSL_RSA_C) rsa_init(&rsa, RSA_PKCS_V15, 0, myrand, NULL); rsa_gen_key(&rsa, 1024, 65537); printf(" RSA-1024 : "); fflush(stdout); set_alarm(3); for (i = 1; !alarmed; i++) { buf[0] = 0; rsa_public(&rsa, buf, buf); } printf("%9lu public/s\n", i / 3); printf(" RSA-1024 : "); fflush(stdout); set_alarm(3); for (i = 1; !alarmed; i++) { buf[0] = 0; rsa_private(&rsa, buf, buf); } printf("%9lu private/s\n\n", i / 3); rsa_free(&rsa); #endif #ifdef WIN32 printf(" Press Enter to exit this program.\n"); fflush(stdout); getchar(); #endif return (0); }
void testMediaDescriptor_GetEndpointData() { const char *sdpOffer = "v=0\r\n" "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\r\n" "s=SDP Seminar\r\n" "i=A Seminar on the session description protocol\r\n" "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\r\n" "[email protected] (Mark Handley)\r\n" "c=IN IP4 10.10.10.1\r\n" "t=2873397496 2873404696\r\n" "m=audio 10000 RTP/AVP 0\r\n" // media description 0 "c=IN IP4 10.10.10.2\r\n" "a=recvonly\r\n" "m=video 10002 RTP/AVP 31\r\n" // media description 1 "a=inactive\r\n" "m=application 10004 udp wb\r\n" // media description 2 "a=sendonly\r\n" "m=audio 10006 RTP/AVP 0\r\n" // media description 3 "c=IN IP4 10.10.10.3\r\n" "a=sendrecv\r\n" "m=audio 10008 RTP/AVP 0\r\n" // media description 4 ; SdpBody offerBody(sdpOffer); const char *sdpAnswer = "v=0\r\n" "o=mhandley 2890844526 2890842807 IN IP4 126.16.64.4\r\n" "s=SDP Seminar\r\n" "i=A Seminar on the session description protocol\r\n" "u=http://www.cs.ucl.ac.uk/staff/M.Handley/sdp.03.ps\r\n" "[email protected] (Mark Handley)\r\n" "c=IN IP4 20.10.10.1\r\n" "t=2873397496 2873404696\r\n" "m=audio 20000 RTP/AVP 0\r\n" // media description 0 "c=IN IP4 20.10.10.2\r\n" "a=recvonly\r\n" "m=video 20002 RTP/AVP 31\r\n" // media description 1 "a=inactive\r\n" "m=application 20004 udp wb\r\n" // media description 2 "a=sendonly\r\n" "m=audio 20006 RTP/AVP 0\r\n" // media description 3 "c=IN IP4 20.10.10.3\r\n" "a=sendrecv\r\n" "m=audio 20008 RTP/AVP 0\r\n" // media description 4 ; SdpBody answerBody(sdpAnswer); MediaDescriptor md0( offerBody, 0, CALLER ); MediaDescriptor md1( offerBody, 1, CALLER ); MediaDescriptor md2( offerBody, 2, CALLER ); MediaDescriptor md3( offerBody, 3, CALLER ); MediaDescriptor md4( offerBody, 4, CALLER ); md0.setEndpointData( answerBody, 0, CALLEE ); md1.setEndpointData( answerBody, 1, CALLEE ); md2.setEndpointData( answerBody, 2, CALLEE ); md3.setEndpointData( answerBody, 3, CALLEE ); md4.setEndpointData( answerBody, 4, CALLEE ); MediaEndpoint mediaEndpoint; // Media Descriptor 0 mediaEndpoint = md0.getEndpoint( CALLER ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "10.10.10.2" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 10000 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 10001 ); mediaEndpoint = md0.getEndpoint( CALLEE ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "20.10.10.2" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 20000 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 20001 ); // Media Descriptor 1 mediaEndpoint = md1.getEndpoint( CALLER ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "10.10.10.1" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 10002 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 10003 ); mediaEndpoint = md1.getEndpoint( CALLEE ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "20.10.10.1" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 20002 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 20003 ); // Media Descriptor 2 mediaEndpoint = md2.getEndpoint( CALLER ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "10.10.10.1" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 10004 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 10005 ); mediaEndpoint = md2.getEndpoint( CALLEE ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "20.10.10.1" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 20004 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 20005 ); // Media Descriptor 3 mediaEndpoint = md3.getEndpoint( CALLER ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "10.10.10.3" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 10006 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 10007 ); mediaEndpoint = md3.getEndpoint( CALLEE ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "20.10.10.3" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 20006 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 20007 ); // Media Descriptor 4 mediaEndpoint = md4.getEndpoint( CALLER ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "10.10.10.1" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 10008 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 10009 ); mediaEndpoint = md4.getEndpoint( CALLEE ); CPPUNIT_ASSERT( mediaEndpoint.getAddress() == "20.10.10.1" ); CPPUNIT_ASSERT( mediaEndpoint.getRtpPort() == 20008 ); CPPUNIT_ASSERT( mediaEndpoint.getRtcpPort() == 20009 ); }
static Auth * auth_ntlmv2(char *windom, char *keyp, uchar *chal, int len) { int i, n; Rune r; char *p, *u; uchar v1hash[MD5dlen], blip[Bliplen], blob[1024], v2hash[MD5dlen]; uchar c, lm_hmac[MD5dlen], nt_hmac[MD5dlen], nt_sesskey[MD5dlen], lm_sesskey[MD5dlen]; DigestState *ds; UserPasswd *up; static Auth *ap; up = auth_getuserpasswd(auth_getkey, "windom=%s proto=pass service=cifs-ntlmv2 %s", windom, keyp); if(!up) sysfatal("cannot get key - %r"); ap = emalloc9p(sizeof(Auth)); memset(ap, 0, sizeof(ap)); /* Standard says unlimited length, experience says 128 max */ if((n = strlen(up->passwd)) > 128) n = 128; ds = md4(nil, 0, nil, nil); for(i=0, p=up->passwd; i < n; i++) { p += chartorune(&r, p); c = r; md4(&c, 1, nil, ds); c = r >> 8; md4(&c, 1, nil, ds); } md4(nil, 0, v1hash, ds); /* * Some documentation insists that the username must be forced to * uppercase, but the domain name should not be. Other shows both * being forced to uppercase. I am pretty sure this is irrevevant as the * domain name passed from the remote server always seems to be in * uppercase already. */ ds = hmac_t64(nil, 0, v1hash, MD5dlen, nil, nil); u = up->user; while(*u){ u += chartorune(&r, u); r = toupperrune(r); c = r; hmac_t64(&c, 1, v1hash, MD5dlen, nil, ds); c = r >> 8; hmac_t64(&c, 1, v1hash, MD5dlen, nil, ds); } u = windom; while(*u){ u += chartorune(&r, u); c = r; hmac_t64(&c, 1, v1hash, MD5dlen, nil, ds); c = r >> 8; hmac_t64(&c, 1, v1hash, MD5dlen, nil, ds); } hmac_t64(nil, 0, v1hash, MD5dlen, v2hash, ds); ap->user = estrdup9p(up->user); ap->windom = estrdup9p(windom); /* LM v2 */ genrandom(blip, Bliplen); ds = hmac_t64(chal, len, v2hash, MD5dlen, nil, nil); hmac_t64(blip, Bliplen, v2hash, MD5dlen, lm_hmac, ds); ap->len[0] = MD5dlen+Bliplen; ap->resp[0] = emalloc9p(ap->len[0]); memcpy(ap->resp[0], lm_hmac, MD5dlen); memcpy(ap->resp[0]+MD5dlen, blip, Bliplen); /* LM v2 session key */ hmac_t64(lm_hmac, MD5dlen, v2hash, MD5dlen, lm_sesskey, nil); /* LM v2 MAC key */ ap->mackey[0] = emalloc9p(MACkeylen); memcpy(ap->mackey[0], lm_sesskey, MD5dlen); memcpy(ap->mackey[0]+MD5dlen, ap->resp[0], MACkeylen-MD5dlen); /* NTLM v2 */ n = ntv2_blob(blob, sizeof(blob), windom); ds = hmac_t64(chal, len, v2hash, MD5dlen, nil, nil); hmac_t64(blob, n, v2hash, MD5dlen, nt_hmac, ds); ap->len[1] = MD5dlen+n; ap->resp[1] = emalloc9p(ap->len[1]); memcpy(ap->resp[1], nt_hmac, MD5dlen); memcpy(ap->resp[1]+MD5dlen, blob, n); /* * v2hash definitely OK by * the time we get here. */ /* NTLM v2 session key */ hmac_t64(nt_hmac, MD5dlen, v2hash, MD5dlen, nt_sesskey, nil); /* NTLM v2 MAC key */ ap->mackey[1] = emalloc9p(MACkeylen); memcpy(ap->mackey[1], nt_sesskey, MD5dlen); memcpy(ap->mackey[1]+MD5dlen, ap->resp[1], MACkeylen-MD5dlen); free(up); return ap; }
int main( void ) { int keysize; unsigned long i, j, tsc; unsigned char tmp[64]; t_cpu_time timer; /* Keep compiler happy */ UNUSED(keysize); UNUSED(i); UNUSED(j); UNUSED(tsc); UNUSED(tmp[0]); UNUSED(timer); // USART options. static usart_serial_options_t USART_SERIAL_OPTIONS = { .baudrate = USART_SERIAL_EXAMPLE_BAUDRATE, .charlength = USART_SERIAL_CHAR_LENGTH, .paritytype = USART_SERIAL_PARITY, .stopbits = USART_SERIAL_STOP_BIT }; sysclk_init(); // Initialize the board. // The board-specific conf_board.h file contains the configuration of the board // initialization. board_init(); // Initialize Serial Interface using Stdio Library stdio_serial_init(USART_SERIAL_EXAMPLE,&USART_SERIAL_OPTIONS); printf( "Start Benchmark\n"); #if defined(POLARSSL_ARC4_C) arc4_context arc4; #endif #if defined(POLARSSL_DES_C) des3_context des3; des_context des; #endif #if defined(POLARSSL_AES_C) aes_context aes; #endif #if defined(POLARSSL_CAMELLIA_C) camellia_context camellia; #endif #if defined(POLARSSL_RSA_C) rsa_context rsa; #endif memset( buf, 0xAA, sizeof( buf ) ); printf( "\n" ); #if defined(POLARSSL_MD4_C) printf( " MD4 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) md4( buf, BUFSIZE, tmp ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) md4( buf, BUFSIZE, tmp ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_MD5_C) printf( " MD5 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) md5( buf, BUFSIZE, tmp ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) md5( buf, BUFSIZE, tmp ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_SHA1_C) printf( " SHA-1 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) sha1( buf, BUFSIZE, tmp ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) sha1( buf, BUFSIZE, tmp ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_SHA2_C) printf( " SHA-256 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) sha2( buf, BUFSIZE, tmp, 0 ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) sha2( buf, BUFSIZE, tmp, 0 ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_SHA4_C) printf( " SHA-512 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) sha4( buf, BUFSIZE, tmp, 0 ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) sha4( buf, BUFSIZE, tmp, 0 ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_ARC4_C) printf( " ARC4 : " ); fflush( stdout ); arc4_setup( &arc4, tmp, 32 ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) arc4_crypt( &arc4, BUFSIZE, buf, buf ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) arc4_crypt( &arc4, BUFSIZE, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_DES_C) printf( " 3DES : " ); fflush( stdout ); des3_set3key_enc( &des3, tmp ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); printf( " DES : " ); fflush( stdout ); des_setkey_enc( &des, tmp ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 1024; j++ ) des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); #endif #if defined(POLARSSL_AES_C) for( keysize = 128; keysize <= 256; keysize += 64 ) { printf( " AES-%d : ", keysize ); fflush( stdout ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); aes_setkey_enc( &aes, tmp, keysize ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 4096; j++ ) aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); } #endif #if defined(POLARSSL_CAMELLIA_C) for( keysize = 128; keysize <= 256; keysize += 64 ) { printf( " CAMELLIA-%d : ", keysize ); fflush( stdout ); memset( buf, 0, sizeof( buf ) ); memset( tmp, 0, sizeof( tmp ) ); camellia_setkey_enc( &camellia, tmp, keysize ); cpu_set_timeout(cpu_ms_2_cy(1000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ); tsc = hardclock(); for( j = 0; j < 4096; j++ ) camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf ); printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024, ( hardclock() - tsc ) / ( j * BUFSIZE ) ); } #endif #if defined(POLARSSL_RSA_C) rsa_init( &rsa, RSA_PKCS_V15, 0 ); rsa_gen_key( &rsa, myrand, NULL, 1024, 65537 ); printf( " RSA-1024 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) { buf[0] = 0; rsa_public( &rsa, buf, buf ); } printf( "%9lu public/s\n", i / 3 ); printf( " RSA-1024 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) { buf[0] = 0; rsa_private( &rsa, buf, buf ); } printf( "%9lu private/s\n", i / 3 ); rsa_free( &rsa ); rsa_init( &rsa, RSA_PKCS_V15, 0 ); rsa_gen_key( &rsa, myrand, NULL, 2048, 65537 ); printf( " RSA-2048 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) { buf[0] = 0; rsa_public( &rsa, buf, buf ); } printf( "%9lu public/s\n", i / 3 ); printf( " RSA-2048 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); for( i = 1; ! cpu_is_timeout(&timer); i++ ) { buf[0] = 0; rsa_private( &rsa, buf, buf ); } printf( "%9lu private/s\n", i / 3 ); rsa_free( &rsa ); rsa_init( &rsa, RSA_PKCS_V15, 0 ); rsa_gen_key( &rsa, myrand, NULL, 4096, 65537 ); printf( " RSA-4096 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); for( i = 1; !cpu_is_timeout(&timer); i++ ) { buf[0] = 0; rsa_public( &rsa, buf, buf ); } printf( "%9lu public/s\n", i / 3 ); printf( " RSA-4096 : " ); fflush( stdout ); cpu_set_timeout(cpu_ms_2_cy(3000, CPU_HZ),&timer); for( i = 1; ! cpu_is_timeout(&timer); i++ ) { buf[0] = 0; rsa_private( &rsa, buf, buf ); } printf( "%9lu private/s\n", i / 3 ); rsa_free( &rsa ); #endif printf( "\n" ); #ifdef WIN32 printf( " Press Enter to exit this program.\n" ); fflush( stdout ); getchar(); #endif return( 0 ); }
void mschap(Ticketreq *tr) { char *secret, *hkey; char sbuf[SECRETLEN], hbuf[DESKEYLEN]; uchar chal[CHALLEN]; uchar hash[MShashlen]; uchar hash2[MShashlen]; uchar resp[MSresplen]; OMSchapreply reply; int dupe, lmok, ntok; DigestState *s; uchar digest[SHA1dlen]; /* * Create a challenge and send it. */ randombytes((uchar*)chal, sizeof(chal)); write(1, chal, sizeof(chal)); /* * get chap reply */ if(readn(0, &reply, sizeof(reply)) < 0) exits(0); safecpy(tr->uid, reply.uid, sizeof(tr->uid)); /* * lookup */ secret = findsecret(KEYDB, tr->uid, sbuf); hkey = findkey(KEYDB, tr->hostid, hbuf); if(hkey == 0 || secret == 0){ replyerror("mschap-fail bad response %s/%s(%s)", tr->uid, tr->hostid, raddr); logfail(tr->uid); exits(0); } lmhash(hash, secret); mschalresp(resp, hash, chal); lmok = memcmp(resp, reply.LMresp, MSresplen) == 0; nthash(hash, secret); mschalresp(resp, hash, chal); ntok = memcmp(resp, reply.NTresp, MSresplen) == 0; dupe = memcmp(reply.LMresp, reply.NTresp, MSresplen) == 0; /* * It is valid to send the same response in both the LM and NTLM * fields provided one of them is correct, if neither matches, * or the two fields are different and either fails to match, * the whole sha-bang fails. * * This is an improvement in security as it allows clients who * wish to do NTLM auth (which is insecure) not to send * LM tokens (which is very insecure). * * Windows servers supports clients doing this also though * windows clients don't seem to use the feature. */ if((!ntok && !lmok) || ((!ntok || !lmok) && !dupe)){ replyerror("mschap-fail bad response %s/%s(%s) %d,%d,%d", tr->uid, tr->hostid, raddr, dupe, lmok, ntok); logfail(tr->uid); exits(0); } succeed(tr->uid); /* * reply with ticket & authenticator */ if(tickauthreply(tr, hkey) < 0) exits(0); if(debug) replyerror("mschap-ok %s/%s(%s) %ux", tr->uid, tr->hostid, raddr); nthash(hash, secret); md4(hash, 16, hash2, 0); s = sha1(hash2, 16, 0, 0); sha1(hash2, 16, 0, s); sha1(chal, 8, digest, s); if(write(1, digest, 16) < 0) exits(0); }