|
Document of c-modernization-kit (porter) 1.0.0
|
データ暗号化・復号モジュールの内部ヘッダー。 More...
Go to the source code of this file.
Functions | |
| int | potr_encrypt (uint8_t *dst, size_t *dst_len, const uint8_t *src, size_t src_len, const uint8_t *key, const uint8_t *nonce, const uint8_t *aad, size_t aad_len) |
| AES-256-GCM でデータを暗号化します。 | |
| int | potr_decrypt (uint8_t *dst, size_t *dst_len, const uint8_t *src, size_t src_len, const uint8_t *key, const uint8_t *nonce, const uint8_t *aad, size_t aad_len) |
| AES-256-GCM でデータを復号し、認証タグを検証します。 | |
| int | potr_passphrase_to_key (uint8_t *key, const uint8_t *passphrase, size_t passphrase_len) |
| 任意のパスフレーズを SHA-256 ハッシュにより AES-256 鍵に変換します。 | |
データ暗号化・復号モジュールの内部ヘッダー。
プラットフォームごとに異なる暗号 API を共通インターフェースで抽象化します。
| OS | 使用ライブラリ | アルゴリズム |
|---|---|---|
| Linux | OpenSSL (libcrypto) EVP_aes_256_gcm() / EVP_sha256() | AES-256-GCM / SHA-256 |
| Windows | CNG (BCrypt) BCRYPT_AES_ALGORITHM / BCRYPT_SHA256_ALGORITHM | AES-256-GCM / SHA-256 |
暗号化ペイロードのフォーマット:
ノンス構成 (12 バイト):
追加認証データ (AAD): PotrPacket ヘッダー 32 バイト (NBO ワイヤーフォーマット)。 ヘッダーの改ざんも認証タグで検知される。
Definition in file crypto.h.
|
extern |
AES-256-GCM でデータを暗号化します。
| [out] | dst | 暗号化後データを格納するバッファ。 内容: [暗号文: src_len バイト][GCM タグ: POTR_CRYPTO_TAG_SIZE バイト] dst == src の in-place 暗号化も可能。 |
| [in,out] | dst_len | 入力: dst のバッファサイズ (>= src_len + POTR_CRYPTO_TAG_SIZE)。 出力: 書き込んだバイト数 (= src_len + POTR_CRYPTO_TAG_SIZE)。 |
| [in] | src | 平文データへのポインタ。 |
| [in] | src_len | 平文データのバイト数。 |
| [in] | key | AES-256 鍵 (POTR_CRYPTO_KEY_SIZE バイト)。 |
| [in] | nonce | ノンス (POTR_CRYPTO_NONCE_SIZE バイト)。 |
| [in] | aad | 追加認証データへのポインタ。NULL の場合は AAD なし。 |
| [in] | aad_len | AAD のバイト数。 |
Definition at line 29 of file crypto_linux.c.
References POTR_CRYPTO_NONCE_SIZE, and POTR_CRYPTO_TAG_SIZE.
Referenced by flush_packed(), flush_packed_peer(), health_thread_func(), n1_send_nack(), n1_send_ping_reply(), n1_send_reject(), peer_send_fin(), send_fin(), send_nack(), send_ping_reply(), send_reject(), tcp_health_thread_func(), and tcp_send_ping_reply().
|
extern |
AES-256-GCM でデータを復号し、認証タグを検証します。
| [out] | dst | 復号後データを格納するバッファ。 |
| [in,out] | dst_len | 入力: dst のバッファサイズ (>= src_len - POTR_CRYPTO_TAG_SIZE)。 出力: 書き込んだバイト数 (= src_len - POTR_CRYPTO_TAG_SIZE)。 |
| [in] | src | 暗号化データへのポインタ。 内容: [暗号文: src_len - POTR_CRYPTO_TAG_SIZE バイト][GCM タグ: POTR_CRYPTO_TAG_SIZE バイト] |
| [in] | src_len | 暗号化データのバイト数 (タグを含む)。>= POTR_CRYPTO_TAG_SIZE。 |
| [in] | key | AES-256 鍵 (POTR_CRYPTO_KEY_SIZE バイト)。 |
| [in] | nonce | ノンス (POTR_CRYPTO_NONCE_SIZE バイト)。 |
| [in] | aad | 追加認証データへのポインタ。NULL の場合は AAD なし。 |
| [in] | aad_len | AAD のバイト数。 |
Definition at line 116 of file crypto_linux.c.
References POTR_CRYPTO_NONCE_SIZE, and POTR_CRYPTO_TAG_SIZE.
Referenced by recv_thread_func(), and tcp_recv_thread_func().
|
extern |
任意のパスフレーズを SHA-256 ハッシュにより AES-256 鍵に変換します。
設定ファイルの encrypt_key に 64 文字 hex 以外の文字列が指定された場合に使用します。
入力バイト列の SHA-256 ダイジェストをそのまま鍵として使用します。
送受信の双方で同一のパスフレーズを指定すれば、同一の鍵が導出されます。
| [out] | key | 出力鍵バッファ (POTR_CRYPTO_KEY_SIZE = 32 バイト)。 |
| [in] | passphrase | パスフレーズへのポインタ (任意のバイト列)。 |
| [in] | passphrase_len | パスフレーズの長さ (バイト)。0 の場合も有効。 |
Definition at line 213 of file crypto_linux.c.
References POTR_CRYPTO_KEY_SIZE.
Referenced by apply_service_kv().