mycipher.h
最終更新:2009/10/19
001: /* mycipher.h 002: * EVP 関数による暗号化・復号のサンプル 003: */ 004: 005: #ifndef _MYCIPHER_H_ 006: #define _MYCIPHER_H_ 007: 008: #ifndef _APR_BUCKETS_H_ 009: #include "apr_buckets.h" 010: #endif 011: 012: #ifndef HEADER_ENVELOPE_H 013: #include <openssl/evp.h> 014: #endif 015: 016: #ifndef _MYBB_H_ 017: #include "mybb.h" 018: #endif 019: 020: /* 暗号化に使用するバッファサイズ(バイト長) 021: * 128bits = 16bytes, 192bits = 24bytes, 256bits = 32bytes の公倍数にしてみる 022: */ 023: #define ENCDEC_BUFF_SIZE 1536 024: 025: /* 026: * mycipher.c の初期化 027: * メインスレッドで最初に実行しておく 028: */ 029: 030: void init_mycipher(); 031: 032: 033: /* 034: * ストリームを暗号化・復号する関数(Bucket Brigade ストリーム版) 035: * 返り値: 036: * 0 失敗 037: * 1 成功 038: */ 039: 040: int kencdec_from_bb_to_bb( 041: char *cipher_alg /* IN:暗号アルゴリズム。OpenSSL の指定に基づく。暗号名+"-"+鍵長+"-"+暗号モード */ 042: , unsigned char *keyData /* IN:暗号鍵のオクテット列 */ 043: , int keyLen /* IN:暗号鍵の長さ(オクテット長) */ 044: , unsigned char *ivData /* IN:初期化ベクトルのオクテット列 */ 045: , int ivLen /* IN:初期化ベクトルの長さ(オクテット長) */ 046: , int num_in /* IN:暗号対象データのサイズ */ 047: , apr_bucket_brigade *bbIn /* IN:入力ストリーム */ 048: , apr_bucket_brigade *bbOut/* OUT:出力ストリーム */ 049: , int type /* IN:処理タイプ。1:暗号化、0:復号 */ 050: ); 051: 052: /* 053: * ストリームの暗号化(マクロ) 054: */ 055: #define kencrypt_from_bb_to_bb(ca,kd,kl,ivd,ivl,ni,bi,bo) \ 056: kencdec_from_bb_to_bb((ca),(kd),(kl),(ivd),(ivl),(ni),(bi),(bo),(1)) 057: 058: /* 059: * ストリームの復号(マクロ 060: */ 061: #define kdecrypt_from_bb_to_bb(ca,kd,kl,ivd,ivl,ni,bi,bo) \ 062: kencdec_from_bb_to_bb((ca),(kd),(kl),(ivd),(ivl),(ni),(bi),(bo),(0)) 063: 064: #endif /* _MYCIPHER_H_ */
KAKU PROJECT (2009) |