kcrypt_fp.c
最終更新:2009/10/18
001: /* kcrypt_fp.c 002: * 暗号化・復号のサンプル 003: */ 004: 005: #define USAGE "Usage: kcrypt <cipher_alg> <enc | dec> <input_file> <output_file>" 006: /* 007: cipher_alg = "camellia-128-cbc" 008: */ 009: 010: 011: #include <stdio.h> 012: #include <string.h> 013: #include <openssl/evp.h> 014: /* 015: #include <openssl/err.h> 016: #include <openssl/crypto.h> 017: */ 018: 019: #include "mycipher_fp.h" 020: 021: int main (int ac, char **av) { 022: 023: 024: char *cipher_alg = NULL; 025: char *encdec = NULL; 026: char *input_file = NULL; 027: char *output_file = NULL; 028: int enc = 0; 029: 030: if (ac < 5) { 031: fprintf(stderr, "%s\n", USAGE); 032: goto _ERROR_; 033: } 034: 035: cipher_alg = av[1]; 036: encdec = av[2]; 037: input_file = av[3]; 038: output_file = av[4]; 039: 040: if (!strcmp(encdec, "enc")) { 041: enc = 1; 042: } 043: 044: if (1) { 045: FILE *fpin = NULL; 046: FILE *fpout = NULL; 047: 048: /* メモ:鍵やIVは乱数にするのが普通だけど…。 */ 049: 050: if (!(fopen_s(&fpin, input_file, "rb")) && !(fopen_s(&fpout, output_file, "wb"))) { 051: if (enc) { 052: kencrypt_from_FP_to_FP(cipher_alg, "0123456789ABCDEF", 16, "This is a pencil", 16, fpin, fpout); 053: } else { 054: kdecrypt_from_FP_to_FP(cipher_alg, "0123456789ABCDEF", 16, "This is a pencil", 16, fpin, fpout); 055: } 056: 057: fclose(fpout); 058: fclose(fpin); 059: } 060: } 061: 062: printf("\ndone.\n"); 063: 064: return 0; /* 正常終了 */ 065: 066: _ERROR_: 067: 068: fprintf(stderr, "failed!\n"); 069: 070: return 1; /* 異常終了 */ 071: 072: } /* end of main */ 073:
KAKU PROJECT (2009) |