uint16_t dcrypt(uint8_t* src, uint8_t* dst, uint16_t len) { uint8_t key[16]; //Build pinHash from globalArgs.pin memcpy(key,globalArgs.pin,4); memcpy(&key[4],globalArgs.pin,4); memcpy(&key[8],globalArgs.pin,4); memcpy(&key[12],globalArgs.pin,4); uint16_t i; uint8_t* ptr_src; uint8_t* ptr_dst; uint8_t swap[4]; // change 32 bit endiannes to be as same as the device for(i=0; i<sizeof(key); i+=4) { swap[0] = key[i]; swap[1] = key[i+1]; swap[2] = key[i+2]; swap[3] = key[i+3]; key[i] = swap[3]; key[i+1] = swap[2]; key[i+2] = swap[1]; key[i+3] = swap[0]; } ptr_src = src; // change 32 bit endiannes to be as same as the device for(i=0; i<len; i+=4) { swap[0] = ptr_src[i]; swap[1] = ptr_src[i+1]; swap[2] = ptr_src[i+2]; swap[3] = ptr_src[i+3]; ptr_src[i] = swap[3]; ptr_src[i+1] = swap[2]; ptr_src[i+2] = swap[1]; ptr_src[i+3] = swap[0]; } struct NESSIEstruct keystruct; NESSIEkeysetup (key,&keystruct); ptr_src = src; ptr_dst = dst; for(i=0; i<len; i+=16) { NESSIEdecrypt (&keystruct,ptr_src,ptr_dst); ptr_src += 16; ptr_dst += 16; } ptr_src = dst; // change 32 bit endiannes to be as same as the device for(i=0; i<len; i+=4) { swap[0] = ptr_src[i]; swap[1] = ptr_src[i+1]; swap[2] = ptr_src[i+2]; swap[3] = ptr_src[i+3]; ptr_src[i] = swap[3]; ptr_src[i+1] = swap[2]; ptr_src[i+2] = swap[1]; ptr_src[i+3] = swap[0]; } return i; }
/* Encryption routine */ void JehutyEncrypt() { struct NESSIEstruct sp; char key[KEYSIZE]; char plaintext[1024]; /*blocks are 16byte long. But with 16 bytes *there's a problem in encryption so I have *to use 1024byte... can't say why*/ unsigned char plainblock[1024]; unsigned char cipherblock[1024]; char *p; int i=0, j=0, k=0; int c=0; printf("Jehuty Short Message Encryption\nby Giovanni Santostefano\n\n"); /* Enter the key of max 16 chars*/ printf("Insert passphrase(max 16 chars)> "); GetText(key, KEYSIZE); /* print on screen to make entered passphrase unvisible */ for(i=0;i<6000; i++)printf("\n%d\n",6000-i); /* Create Anubis key based on the passphrase */ NESSIEkeysetup(key, &sp); printf("\n\n\n\n\n\n\nJehuty Encrypt text\nby Giovanni Santostefano\n\n"); while(1) { memset(plaintext,0,1024); printf("\n\nInsert text to encrypt (max 1023 characters)\n> "); GetText(plaintext, 1023); p=plaintext; j=0; memset(plainblock,0,1024); memset(cipherblock,0,1024); printf("\n\n<Encrypted! Cut and paste>\n"); while(*p!='\0') { plainblock[j++]=*p++; /* 128bit block filled, encrypt */ if(j>=16 || *p=='\0') { j=0; NESSIEencrypt(&sp, plainblock, cipherblock); /* print the encrypted 128bit block in human readable chars */ for(k=0; k<16; k++) { c=cipherblock[k]; char g=(char)('!'+(c & 0x0f)); printf("%c",g); g=(char)('!'+((c & 0xf0)>>4)); printf("%c",g); } memset(plainblock,0,1024); memset(cipherblock,0,1024); } } }