int main(int argc, char **argv) { char *input, *output; unsigned char *input_data; struct stat in_st; int input_fd, output_fd; int i; unsigned char tmp[64]; ECRYPT_ctx ctx; if (argc != 3) { fprintf(stderr, "usage: %s input output\n", argv[0]); exit(EXIT_FAILURE); } input = argv[1]; output = argv[2]; init_ctx(&ctx); if (stat(input, &in_st) == -1) { perror("stat"); exit(EXIT_FAILURE); } input_fd = open(input, O_RDONLY); if (input_fd == -1) { perror("open"); exit(EXIT_FAILURE); } output_fd = creat(output, S_IRWXU); if (output_fd == -1) { perror("open"); exit(EXIT_FAILURE); } input_data = mmap(NULL, in_st.st_size, PROT_READ, MAP_SHARED, input_fd, 0); if (input_data == (void *) -1) { perror("mmap"); exit(EXIT_FAILURE); } ECRYPT_init(); for (i = 0; i < (in_st.st_size / 64); i++) { ECRYPT_decrypt_bytes(&ctx, input_data + 64 * i, tmp, 64); write(output_fd, tmp, 64); } close(output_fd); munmap(input_data, in_st.st_size); close(input_fd); exit(EXIT_SUCCESS); }
namespace fc { static bool salsa20_init = []() -> bool { ECRYPT_init(); return true; }(); void salsa20_encrypt( const fc::sha256& key, uint64_t iv, const char* plain, char* cipher, uint64_t len ) { ECRYPT_ctx ctx; ECRYPT_keysetup( &ctx, (unsigned char*)&key, ECRYPT_MAXIVSIZE, ECRYPT_MAXKEYSIZE ); ECRYPT_ivsetup( &ctx, (unsigned char*)&iv ); ECRYPT_encrypt_bytes( &ctx, (const unsigned char*)plain, (unsigned char*)cipher, len ); } void salsa20_decrypt( const fc::sha256& key, uint64_t iv, const char* cipher, char* plain, uint64_t len ) { } }
void main() { u8 key_1[10] = {0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34}; u8 key_2[10] = {0xf1, 0x1a, 0x56, 0x27, 0xce, 0x43, 0xb6, 0x1f, 0x89, 0x12}; u8 key_3[10] = {0x3b, 0x80, 0xfc, 0x8c, 0x47, 0x5f, 0xc2, 0x70, 0xfa, 0x26}; u8 key_4[10] = {0x82, 0xac, 0xb3, 0x8c, 0x5d, 0x7a, 0x3c, 0x78, 0xd9, 0x8f}; u8 iv_1[4] = {0x21, 0x43, 0x65, 0x87}; u8 iv_2[10] = {0x9c, 0x53, 0x2f, 0x8a, 0xc3, 0xea, 0x4b, 0x2e, 0xa0, 0xf5}; /* Initialise the algorithm */ ECRYPT_init (); /* Generate the test data */ perform_test (key_1, iv_1, 32); perform_test (key_2, iv_2, 80); perform_test (key_3, NULL, 0); perform_iterated_test (key_4); }
int main() { ECRYPT_ctx ctx; int i,t; u8 key[10]; u8 iv[10]; u8 in[NR_PROC_BYTES],out[NR_PROC_BYTES]; u32 dkey[3],div[3]; xs_rng rng; xs_seed(&rng,time(0)); // xs_seed(&rng,1337); memset(in,0x00,sizeof(in)); memset(out,0x00,sizeof(out)); memset(dkey,0,3*sizeof(u32)); memset(div,0,3*sizeof(u32)); printf("%d\n",NR_TESTS); for(t=0;t<NR_TESTS;t++) { /* memset(key,0xff,sizeof(key)); memset(iv,0xff,sizeof(iv)); */ for(i=0;i<sizeof(key);i++) { int tmp=xs_rand(&rng); key[i]=tmp&0xff; iv[i]=(tmp>>8)&0xff; } // memcpy(dkey,key,sizeof(key)); // memcpy(div,iv,sizeof(iv)); // printf("key:\n"); print_bin_array_u8(key,10); printf("\n"); // printf("iv:\n"); print_bin_array_u8(iv,10); printf("\n"); ECRYPT_init(); ECRYPT_keysetup(&ctx,key,80,80); ECRYPT_ivsetup(&ctx,iv); // printf("state:\n"); print_bin_array_u8(ctx.s,40); printf("\n"); ECRYPT_process_bytes(0,&ctx,in,out,sizeof(in)); print_x32_array(key,3); print_x32_array(iv,3); print_x32_rev_bits(out); printf("\n"); // printf("state:\n"); print_bin_array_u8(ctx.s,40); printf("\n"); // printf("output:\n"); print_bin_array_u8(out,NR_PROC_BYTES); printf("\n"); // printf("\n-----------------------\n"); // printf("dkey:\n"); print_bin_array_u32(dkey,3); printf("\n"); // printf("div:\n"); print_bin_array_u32(div,3); printf("\n"); #if 0 { int term[12]={3,13,18,26,38,40,47,49,55,57,66,79}; int nr_terms=12; u32 const_term=0; int tm; int k; for(tm=-1;tm<80;tm++) { int sum=0,output=0; memset(dkey,0,3*sizeof(u32)); if(tm!=-1) { black_box_key_set_bitpos(dkey,tm); } // printf("dkey:\n"); print_bin_array_u32(dkey,3); printf("\n"); for(k=0;k<(1<<nr_terms);k++) { memset(div,0,3*sizeof(u32)); black_box_id2iv(div,term,12,k); // printf("div[%3d]:\n",k); print_bin_array_u32(div,3); printf("\n"); output=d_trivium(dkey,div,32); sum^=output; } if(tm==-1) { const_term=sum; } else { printf("x_%02d=%08x\n",tm,(sum^const_term)&1); } } } #endif } return 0; }