暗号用ライブラリ More...
#include "cipher.h"
Go to the source code of this file.
Functions | |
void | setkey_byBase64 (Buffer key) |
void | setkey_byBuffer (Buffer key) |
Buffer | encrypt_Buffer (Buffer buf, int mode) |
Buffer | encrypt_Base64 (Buffer buf, int mode) |
Buffer | to_bin64 (Buffer str) |
Buffer | from_bin64 (Buffer str) |
void | dump_bin64 (char *format, Buffer str) |
CentOS8 では encrypt(), setkey() が存在しない?
Definition in file cipher.c.
void dump_bin64 | ( | char * | format, | |
Buffer | str | |||
) |
void dump_bin64(char* format, Buffer str)
bin64形式を標準エラー出力に表示する.
format | bin64の内容を表示する前に表示するタイトル. | |
str | 表示する bin64形式のバイト列 |
Definition at line 174 of file cipher.c.
References Buffer::buf, and Buffer::vldsz.
Buffer encrypt_Base64(Buffer buf, int mode)
文字列の暗号化または復号を行う
暗号化または復号される文字列はBase64でエンコードされている. 内部では一旦 Base64からデコードされて処理がおこなわれ,再びエンコードされる.
この関数を呼ぶ前に, setkey_XXXX()関数で暗号化キーを設定しなければならない.
buf | 暗号化または復号を行う Base64文字列. | |
mode | 0: 暗号化.1: 復号. |
Definition at line 100 of file cipher.c.
References decode_base64_Buffer(), encode_base64_Buffer(), encrypt_Buffer(), and free_Buffer().
00101 { 00102 Buffer dec, str, enc; 00103 00104 dec = decode_base64_Buffer(buf); 00105 str = encrypt_Buffer(dec, mode); 00106 free_Buffer(&dec); 00107 00108 enc = encode_base64_Buffer(str); 00109 free_Buffer(&str); 00110 return enc; 00111 }
Buffer encrypt_Buffer(Buffer buf, int mode)
バイナリデータの暗号化または復号を行う. この関数を呼ぶ前に, setkey_XXXX()関数で暗号化キーを設定しなければならない.
buf | 暗号化または復号を行うデータ. | |
mode | 0: 暗号化.1: 復号. |
Definition at line 72 of file cipher.c.
References Buffer::buf, free_Buffer(), from_bin64(), and to_bin64().
Referenced by encrypt_Base64().
00073 { 00074 Buffer str, cry; 00075 00076 str = to_bin64(buf); 00077 encrypt((char*)str.buf, mode); 00078 cry = from_bin64(str); 00079 free_Buffer(&str); 00080 return cry; 00081 }
0,1のバイト列(64Byte, bin64形式)を 8byteのビット列に変換する.
str | ビット列に変換するバイト列.64Byte. bin64形式. |
Definition at line 148 of file cipher.c.
References Buffer::buf, init_Buffer(), make_Buffer(), setBit, and Buffer::vldsz.
Referenced by encrypt_Buffer().
00149 { 00150 int i; 00151 Buffer ret; 00152 00153 ret = init_Buffer(); 00154 if (str.vldsz!=64) return ret; 00155 00156 ret = make_Buffer(8); 00157 if (ret.buf==NULL) return ret; 00158 00159 for (i=0; i<64; i++) setBit(ret.buf, i, (int)str.buf[i]); 00160 ret.vldsz = 8; 00161 return ret; 00162 }
void setkey_byBase64 | ( | Buffer | key | ) |
void setkey_byBase64(Buffer key)
Base64によってエンコードされた文字列をデコードし,それを encrypt関数の暗号化キーとして設定する.
キー長は通常 8Byte(64bit)だが,有効なものは最初の7Byte(56bit)である.
key | 暗号化のキー |
Definition at line 24 of file cipher.c.
References Buffer::buf, decode_base64_Buffer(), free_Buffer(), and to_bin64().
00025 { 00026 Buffer tmpkey, deskey; 00027 00028 tmpkey = decode_base64_Buffer(key); 00029 deskey = to_bin64(tmpkey); 00030 00031 setkey((const char*)deskey.buf); 00032 free_Buffer(&tmpkey); 00033 free_Buffer(&deskey); 00034 return; 00035 }
void setkey_byBuffer | ( | Buffer | key | ) |
void setkey_byBuffer(Buffer key)
アスキー文字(8Byte)を用いて,encrypt関数の暗号化キーを設定する. ただし,キーとして有もなものは最初の7Byteである.
key | 暗号化のキー |
Definition at line 47 of file cipher.c.
References Buffer::buf, free_Buffer(), and to_bin64().
00048 { 00049 Buffer deskey; 00050 00051 deskey = to_bin64(key); 00052 setkey((const char*)deskey.buf); 00053 free_Buffer(&deskey); 00054 00055 return; 00056 }
Bit列を 0,1のバイト列(64Byte)に変換する (bin64形式に件関する).
例えば、整数の 2は 0,0,0,0,0,.....,0,1,0 のバイト列(64Byte)になる.
str | バイト列に変換するビット列. |
Definition at line 124 of file cipher.c.
References Buffer::buf, getBit, make_Buffer(), Min, and Buffer::vldsz.
Referenced by encrypt_Buffer(), setkey_byBase64(), and setkey_byBuffer().
00125 { 00126 int i, mi; 00127 Buffer ret; 00128 00129 ret = make_Buffer(64); 00130 if (ret.buf==NULL) return ret; 00131 00132 mi = Min(64, str.vldsz*8); 00133 for (i=0; i<mi; i++) ret.buf[i] = (uByte)getBit(str.buf, i); 00134 ret.vldsz = mi; 00135 return ret; 00136 }