delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / kwalletd / backend / tests / testbf.cpp
blob12dc746304f7263bd5701e6a0fa9238e5ca01dbe
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "blowfish.h"
5 #include "cbc.h"
8 int main() {
9 BlockCipher *bf;
10 char data[] = "This is a test.";
11 char expect[] = "\x22\x30\x7e\x2f\x42\x28\x44\x01\xda\xdf\x5a\x81\xd7\xe5\x7c\xd0";
12 char key[] = "testkey";
13 unsigned long et[] = {0x11223344};
15 printf("%d: 0x11 == %d and 0x44 == %d\n", ((unsigned char *)et)[0],
16 0x11, 0x44);
17 bf = new BlowFish();
18 // bf = new CipherBlockChain(new BlowFish());
20 bf->setKey((void *)key, 7*8);
22 if (!bf->readyToGo()) {
23 printf("Error: not ready to go!\n");
24 return -1;
27 printf("About to encrypt...\n"); fflush(stdout);
28 if (-1 == bf->encrypt((void *)data, 8)) {
29 printf("Error: encrypt failed!\n");
30 return -1;
32 printf("About to encrypt part 2...\n"); fflush(stdout);
33 bf->encrypt((void *)(data+8), 8);
35 printf("Encryption done. data[] is now: ");
36 for (int i = 0; i < 16; i++) {
37 printf("0x%x ", data[i]&0xff);
38 if ((data[i]&0xff) != (expect[i]&0xff)) {
39 printf("Error. This byte failed the comparison. It should have been 0x%x.\n", expect[i]&0xff);
40 return -1;
43 printf("\n");
45 delete bf;
46 bf = new BlowFish();
47 // bf = new CipherBlockChain(new BlowFish());
48 bf->setKey((void *)key, 7*8);
50 printf("About to decrypt...\n"); fflush(stdout);
51 if (-1 == bf->decrypt((void *)data, 16)) {
52 printf("Error: decrypt failed!\n");
53 return -1;
55 //bf->decrypt((void *)(data+8), 8);
57 printf("All done! Result... data[] = \"%s\"\n", data);
58 if (strcmp(data, "This is a test.")) {
59 printf("ERROR. Decryption failed.\n");
60 return -1;
63 delete bf;