>>3593 へにか ありがとうございます。お返事は後ほど。 で、メモその 2。EVP 版 blowfish 暗号化・復号化。なお、 http://www.openssl.org/docs/crypto/EVP_EncryptInit.html は古いバージョンの API。OpenSSL の web は本当にひどい。 #include <stdio.h> #include <openssl/evp.h> int do_crypt(FILE *in, FILE *out, int enc_mode){ unsigned char key[]="SECRET!"; unsigned char iv[8]; EVP_CIPHER_CTX ctx; char outbuf[256]; int outlen; memset(iv, 0, sizeof(iv)); EVP_CipherInit(&ctx, EVP_bf_cbc(), key, iv, enc_mode); while (1){ char inbuf[128]; int inlen; inlen = fread(inbuf, sizeof(inbuf[0]), sizeof(inbuf)/sizeof(inbuf[0]), in); if ( inlen==0 ){ break; } EVP_CipherUpdate(&ctx, outbuf, &outlen, inbuf, inlen); fwrite(outbuf, sizeof(outbuf[0]), outlen, out); } EVP_CipherFinal(&ctx, outbuf, &outlen); fwrite(outbuf, sizeof(outbuf[0]), outlen, out); return 0; } int main(int argc, char *argv[]){ int enc_mode; if ( argc == 1 ){ printf("Specify enc or dec.\n"); exit(1); } if ( strcmp(argv[1], "enc") == 0 ){ enc_mode = BF_ENCRYPT; } else if ( strcmp(argv[1], "dec") == 0 ){ enc_mode = BF_DECRYPT; } else { printf("Specify enc or dec.\n"); exit(1); } do_crypt(stdin, stdout, enc_mode); return 0; } |