| 40 | | #ifdef XXX |
|---|
| 41 | | char keydetails[MAXBUF+1]; |
|---|
| 42 | | char keyring_name[MAXBUF+1]; |
|---|
| 43 | | int fd=0; |
|---|
| 44 | | char cmd[MAXBUF+1]; |
|---|
| 45 | | |
|---|
| 46 | | // Initialise OPS |
|---|
| 47 | | ops_init(); |
|---|
| 48 | | |
|---|
| 49 | | char *rsa_nopass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Alpha\nName-Comment: RSA, no passphrase\nName-Email: alpha@test.com\nKey-Length: 1024\n"; |
|---|
| 50 | | // Create temp directory |
|---|
| 51 | | if (!mktmpdir()) |
|---|
| 52 | | return 1; |
|---|
| 53 | | |
|---|
| 54 | | /* |
|---|
| 55 | | * Create a RSA keypair with no passphrase |
|---|
| 56 | | */ |
|---|
| 57 | | |
|---|
| 58 | | snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.alpha"); |
|---|
| 59 | | |
|---|
| 60 | | if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0) |
|---|
| 61 | | { |
|---|
| 62 | | fprintf(stderr,"Can't create key details\n"); |
|---|
| 63 | | return 1; |
|---|
| 64 | | } |
|---|
| 65 | | |
|---|
| 66 | | write(fd,rsa_nopass,strlen(rsa_nopass)); |
|---|
| 67 | | close(fd); |
|---|
| 68 | | |
|---|
| 69 | | snprintf(cmd,MAXBUF,"gpg --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails); |
|---|
| 70 | | system(cmd); |
|---|
| 71 | | |
|---|
| 72 | | // read keyrings |
|---|
| 73 | | snprintf(keyring_name,MAXBUF,"%s/pubring.gpg", dir); |
|---|
| 74 | | ops_keyring_read(&pub_keyring,keyring_name); |
|---|
| 75 | | |
|---|
| 76 | | // read keyring |
|---|
| 77 | | snprintf(keyring_name,MAXBUF,"%s/secring.gpg", dir); |
|---|
| 78 | | ops_keyring_read(&sec_keyring,keyring_name); |
|---|
| 79 | | #endif |
|---|
| 80 | | |
|---|
| 102 | | ops_crypt_any(&crypt, OPS_SA_AES_256); |
|---|
| 103 | | |
|---|
| 104 | | /* |
|---|
| 105 | | AES init |
|---|
| 106 | | using empty IV and key for the moment |
|---|
| 107 | | */ |
|---|
| 108 | | unsigned char *iv=ops_mallocz(crypt.blocksize); |
|---|
| 109 | | unsigned char *key=ops_mallocz(crypt.keysize); |
|---|
| 110 | | snprintf((char *)key, crypt.keysize, "AES_KEY"); |
|---|
| | 45 | unsigned char *iv=NULL; |
|---|
| | 46 | unsigned char *key=NULL; |
|---|
| | 47 | unsigned char *in=NULL; |
|---|
| | 48 | unsigned char *out=NULL; |
|---|
| | 49 | unsigned char *out2=NULL; |
|---|
| | 50 | |
|---|
| | 51 | /* |
|---|
| | 52 | * Initialise Crypt structure |
|---|
| | 53 | * Empty IV, made-up key |
|---|
| | 54 | */ |
|---|
| | 55 | |
|---|
| | 56 | ops_crypt_any(&crypt, alg); |
|---|
| | 57 | iv=ops_mallocz(crypt.blocksize); |
|---|
| | 58 | key=ops_mallocz(crypt.keysize); |
|---|
| | 59 | snprintf((char *)key, crypt.keysize, "MY KEY"); |
|---|
| 128 | | // AES_ecb_encrypt(in,out,crypt.data,AES_ENCRYPT); |
|---|
| 129 | | |
|---|
| 130 | | printf("out:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| 131 | | out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]); |
|---|
| 132 | | printf("out:\t%c %c %c %c %c %c %c %c\n", |
|---|
| 133 | | out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]); |
|---|
| 134 | | |
|---|
| 137 | | // AES_ecb_encrypt(out,out2,crypt.data,AES_DECRYPT); |
|---|
| 138 | | printf("out2:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| 139 | | out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]); |
|---|
| 140 | | printf("out2:\t%c %c %c %c %c %c %c %c\n", |
|---|
| 141 | | out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]); |
|---|
| 142 | | |
|---|
| | 78 | if (verbose) |
|---|
| | 79 | { |
|---|
| | 80 | // plaintext |
|---|
| | 81 | printf("\n"); |
|---|
| | 82 | printf("plaintext: 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| | 83 | in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]); |
|---|
| | 84 | printf("plaintext: %c %c %c %c %c %c %c %c\n", |
|---|
| | 85 | in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]); |
|---|
| | 86 | |
|---|
| | 87 | // encrypted |
|---|
| | 88 | printf("encrypted: 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| | 89 | out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]); |
|---|
| | 90 | printf("encrypted: %c %c %c %c %c %c %c %c\n", |
|---|
| | 91 | out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]); |
|---|
| | 92 | |
|---|
| | 93 | // decrypted |
|---|
| | 94 | printf("decrypted: 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| | 95 | out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]); |
|---|
| | 96 | printf("decrypted: %c %c %c %c %c %c %c %c\n", |
|---|
| | 97 | out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]); |
|---|
| | 98 | } |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| | 101 | #ifndef OPENSSL_NO_IDEA |
|---|
| | 102 | static void test_cfb_idea() |
|---|
| | 103 | { |
|---|
| | 104 | test_cfb(OPS_SA_IDEA); |
|---|
| | 105 | } |
|---|
| | 106 | #endif |
|---|
| | 107 | |
|---|
| | 108 | static void test_cfb_3des() |
|---|
| | 109 | { |
|---|
| | 110 | test_cfb(OPS_SA_TRIPLEDES); |
|---|
| 149 | | // Used for trying low-level OpenSSL tests |
|---|
| 150 | | |
|---|
| 151 | | ops_crypt_t crypt; |
|---|
| 152 | | ops_crypt_any(&crypt, OPS_SA_CAST5); |
|---|
| 153 | | |
|---|
| 154 | | /* |
|---|
| 155 | | * CAST |
|---|
| 156 | | */ |
|---|
| 157 | | unsigned char *iv=NULL; |
|---|
| 158 | | unsigned char *key=NULL; |
|---|
| 159 | | iv=ops_mallocz(crypt.blocksize); |
|---|
| 160 | | key=ops_mallocz(crypt.keysize); |
|---|
| 161 | | // snprintf((char *)key, crypt_cast.keysize, "CAST_KEY"); |
|---|
| 162 | | crypt.set_iv(&crypt, iv); |
|---|
| 163 | | crypt.set_key(&crypt, key); |
|---|
| 164 | | ops_encrypt_init(&crypt); |
|---|
| 165 | | |
|---|
| 166 | | unsigned char *in=ops_mallocz(crypt.blocksize); |
|---|
| 167 | | unsigned char *out=ops_mallocz(crypt.blocksize); |
|---|
| 168 | | unsigned char *out2=ops_mallocz(crypt.blocksize); |
|---|
| 169 | | |
|---|
| 170 | | snprintf((char *)in,crypt.blocksize,"hello"); |
|---|
| 171 | | /* |
|---|
| 172 | | printf("\n"); |
|---|
| 173 | | printf("in:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| 174 | | in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]); |
|---|
| 175 | | printf("in:\t%c %c %c %c %c %c %c %c\n", |
|---|
| 176 | | in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]); |
|---|
| 177 | | */ |
|---|
| 178 | | |
|---|
| 179 | | crypt.block_encrypt(&crypt, out, in); |
|---|
| 180 | | // AES_ecb_encrypt(in,out,crypt.data,AES_ENCRYPT); |
|---|
| 181 | | /* |
|---|
| 182 | | printf("out:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| 183 | | out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]); |
|---|
| 184 | | printf("out:\t%c %c %c %c %c %c %c %c\n", |
|---|
| 185 | | out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]); |
|---|
| 186 | | */ |
|---|
| 187 | | |
|---|
| 188 | | crypt.block_decrypt(&crypt, out2, out); |
|---|
| 189 | | // AES_ecb_encrypt(out,out2,crypt.data,AES_DECRYPT); |
|---|
| 190 | | /* |
|---|
| 191 | | printf("out2:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", |
|---|
| 192 | | out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]); |
|---|
| 193 | | printf("out2:\t%c %c %c %c %c %c %c %c\n", |
|---|
| 194 | | out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]); |
|---|
| 195 | | */ |
|---|
| 196 | | CU_ASSERT(memcmp((char *)in, (char *)out2, strlen((char *)in))==0); |
|---|
| 197 | | |
|---|
| | 115 | test_cfb(OPS_SA_CAST5); |
|---|
| | 116 | } |
|---|
| | 117 | |
|---|
| | 118 | static void test_cfb_aes256() |
|---|
| | 119 | { |
|---|
| | 120 | test_cfb(OPS_SA_AES_256); |
|---|