요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
===========================
Kerberos V Cryptography API
===========================
.. Contents:
- Overview.
- Small Buffer.
- Encoding Type.
- Key Derivation.
- PRF+ Calculation.
- Kc, Ke And Ki Derivation.
- Crypto Functions.
- Preparation Functions.
- Encryption Mode.
- Checksum Mode.
- The krb5enc AEAD algorithm
Overview
========
This API provides Kerberos 5-style cryptography for key derivation, encryption
and checksumming for use in network filesystems and can be used to implement
the low-level crypto that's needed for GSSAPI.
The following crypto types are supported::
KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96
KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96
KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128
KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192
KRB5_ENCTYPE_CAMELLIA128_CTS_CMAC
KRB5_ENCTYPE_CAMELLIA256_CTS_CMAC
KRB5_CKSUMTYPE_HMAC_SHA1_96_AES128
KRB5_CKSUMTYPE_HMAC_SHA1_96_AES256
KRB5_CKSUMTYPE_CMAC_CAMELLIA128
KRB5_CKSUMTYPE_CMAC_CAMELLIA256
KRB5_CKSUMTYPE_HMAC_SHA256_128_AES128
KRB5_CKSUMTYPE_HMAC_SHA384_192_AES256
The API can be included by::
#include <crypto/krb5.h>
Small Buffer
------------
To pass small pieces of data about, such as keys, a buffer structure is
defined, giving a pointer to the data and the size of that data::
struct krb5_buffer {
unsigned int len;
void *data;
};
Encoding Type
=============
The encoding type is defined by the following structure::
struct krb5_enctype {
int etype;
int ctype;
const char *name;
u16 key_bytes;
u16 key_len;
u16 Kc_len;
u16 Ke_len;
u16 Ki_len;
u16 prf_len;
u16 block_len;
u16 conf_len;
u16 cksum_len;
...
};
The fields of interest to the user of the API are as follows:
* ``etype`` and ``ctype`` indicate the protocol number for this encoding
type for encryption and checksumming respectively. They hold
``KRB5_ENCTYPE_*`` and ``KRB5_CKSUMTYPE_*`` constants.
* ``name`` is the formal name of the encoding.
* ``key_len`` and ``key_bytes`` are the input key length and the derived key
length. (I think they only differ for DES, which isn't supported here).
* ``Kc_len``, ``Ke_len`` and ``Ki_len`` are the sizes of the derived Kc, Ke
and Ki keys. Kc is used for in checksum mode; Ke and Ki are used in
encryption mode.
* ``prf_len`` is the size of the result from the PRF+ function calculation.
* ``block_len``, ``conf_len`` and ``cksum_len`` are the encryption block
length, confounder length and checksum length respectively. All three are
used in encryption mode, but only the checksum length is used in checksum
mode.
The encoding type is looked up by number using the following function::
const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype);
Key Derivation
==============
Once the application has selected an encryption type, the keys that will be
used to do the actual crypto can be derived from the transport key.
PRF+ Calculation
----------------
To aid in key derivation, a function to calculate the Kerberos GSSAPI
mechanism's PRF+ is provided::
int crypto_krb5_calc_PRFplus(const struct krb5_enctype *krb5,
const struct krb5_buffer *K,
unsigned int L,
const struct krb5_buffer *S,
struct krb5_buffer *result,
gfp_t gfp);
This can be used to derive the transport key from a source key plus additional
data to limit its use.
Crypto Functions
================
Once the keys have been derived, crypto can be performed on the data. The
caller must leave gaps in the buffer for the storage of the confounder (if
needed) and the checksum when preparing a message for transmission. An enum
and a pair of functions are provided to aid in this::
enum krb5_crypto_mode {
KRB5_CHECKSUM_MODE,
KRB5_ENCRYPT_MODE,
};
size_t crypto_krb5_how_much_buffer(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t data_size, size_t *_offset);
size_t crypto_krb5_how_much_data(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t *_buffer_size, size_t *_offset);
All these functions take the encoding type and an indication the mode of crypto
(checksum-only or full encryption).
The first function returns how big the buffer will need to be to house a given
amount of data; the second function returns how much data will fit in a buffer
of a particular size, and adjusts down the size of the required buffer
accordingly. In both cases, the offset of the data within the buffer is also
returned.
When a message has been received, the location and size of the data with the
message can be determined by calling::
int crypto_krb5_where_is_the_data(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t *_offset, size_t *_len);
The caller provides the offset and length of the message to the function, which
then alters those values to indicate the region containing the data (plus any
padding). It is up to the caller to determine how much padding there is. The
function returns an error if the length is too small or if the mode is
unsupported. An additional function::
int crypto_krb5_check_data_len(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t len, size_t min_content);
is provided to just do a basic check that the decrypted/verified message would
have a sufficient minimum payload.
Preparation Functions
---------------------
Two functions are provided to allocated and prepare a crypto object for use by
the action functions::
struct crypto_aead *
crypto_krb5_prepare_encryption(const struct krb5_enctype *krb5,
const struct krb5_buffer *TK,
u32 usage, gfp_t gfp);
struct crypto_shash *
crypto_krb5_prepare_checksum(const struct krb5_enctype *krb5,
const struct krb5_buffer *TK,
u32 usage, gfp_t gfp);
Both of these functions take the encoding type, the transport key and the usage
value used to derive the appropriate subkey(s). They create an appropriate
crypto object, an AEAD template for encryption and a synchronous hash for
checksumming, set the key(s) on it and configure it. The caller is expected to
pass these handles to the action functions below.
Encryption Mode
---------------
A pair of functions are provided to encrypt and decrypt a message::
ssize_t crypto_krb5_encrypt(const struct krb5_enctype *krb5,
struct crypto_aead *aead,
struct scatterlist *sg, unsigned int nr_sg,
size_t sg_len,
size_t data_offset, size_t data_len,
bool preconfounded);
int crypto_krb5_decrypt(const struct krb5_enctype *krb5,
struct crypto_aead *aead,
struct scatterlist *sg, unsigned int nr_sg,
size_t *_offset, size_t *_len);
In both cases, the input and output buffers are indicated by the same
scatterlist.
For the encryption function, the output buffer may be larger than is needed
(the amount of output generated is returned) and the location and size of the
data are indicated (which must match the encoding). If no confounder is set,
the function will insert one.
For the decryption function, the offset and length of the message in buffer are
supplied and these are shrunk to fit the data. The decryption function will
verify any checksums within the message and give an error if they don't match.
Checksum Mode
-------------
A pair of function are provided to generate the checksum on a message and to
verify that checksum::
ssize_t crypto_krb5_get_mic(const struct krb5_enctype *krb5,
struct crypto_shash *shash,
const struct krb5_buffer *metadata,
struct scatterlist *sg, unsigned int nr_sg,
size_t sg_len,
size_t data_offset, size_t data_len);
int crypto_krb5_verify_mic(const struct krb5_enctype *krb5,
struct crypto_shash *shash,
const struct krb5_buffer *metadata,
struct scatterlist *sg, unsigned int nr_sg,
size_t *_offset, size_t *_len);
In both cases, the input and output buffers are indicated by the same
scatterlist. Additional metadata can be passed in which will get added to the
hash before the data.
For the get_mic function, the output buffer may be larger than is needed (the
amount of output generated is returned) and the location and size of the data
are indicated (which must match the encoding).
For the verification function, the offset and length of the message in buffer
are supplied and these are shrunk to fit the data. An error will be returned
if the checksums don't match.
The krb5enc AEAD algorithm
==========================
A template AEAD crypto algorithm, called "krb5enc", is provided that hashes the
plaintext before encrypting it (the reverse of authenc). The handle returned
by ``crypto_krb5_prepare_encryption()`` may be one of these, but there's no
requirement for the user of this API to interact with it directly.
For reference, its key format begins with a BE32 of the format number. Only
format 1 is provided and that continues with a BE32 of the Ke key length
followed by a BE32 of the Ki key length, followed by the bytes from the Ke key
and then the Ki key.
Using specifically ordered words means that the static test data doesn't
require byteswapping.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Kerberos V Cryptography API와 목차
1-20SPDX 라이선스 식별자: GPL-2.0
Kerberos V Cryptography API
목차
- 개요
- 개요 > 작은 buffer
- encoding type
- key derivation
- key derivation > PRF+ 계산
- key derivation > Kc, Ke, Ki 유도
- crypto 함수
- crypto 함수 > 준비 함수
- crypto 함수 > encryption mode
- crypto 함수 > checksum mode
- `krb5enc` AEAD 알고리즘
개요
21-47개요
이 API는 network filesystem에서 사용할 key derivation, encryption, checksum 계산을 위해 Kerberos 5 방식의 암호 기능을 제공하며, GSSAPI에 필요한 low-level crypto를 구현하는 데 사용할 수 있습니다.
다음 crypto type을 지원합니다.
KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96
KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96
KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128
KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192
KRB5_ENCTYPE_CAMELLIA128_CTS_CMAC
KRB5_ENCTYPE_CAMELLIA256_CTS_CMAC
KRB5_CKSUMTYPE_HMAC_SHA1_96_AES128
KRB5_CKSUMTYPE_HMAC_SHA1_96_AES256
KRB5_CKSUMTYPE_CMAC_CAMELLIA128
KRB5_CKSUMTYPE_CMAC_CAMELLIA256
KRB5_CKSUMTYPE_HMAC_SHA256_128_AES128
KRB5_CKSUMTYPE_HMAC_SHA384_192_AES256
다음과 같이 API header를 포함할 수 있습니다.
#include <crypto/krb5.h>
작은 buffer
48-58작은 buffer
key와 같은 작은 데이터 조각을 전달하기 위해 데이터 pointer와 데이터 크기를 담는 buffer 구조체를 정의합니다.
struct krb5_buffer {
unsigned int len;
void *data;
};
encoding type 구조체
59-79encoding type
encoding type은 다음 구조체로 정의합니다.
struct krb5_enctype {
int etype;
int ctype;
const char *name;
u16 key_bytes;
u16 key_len;
u16 Kc_len;
u16 Ke_len;
u16 Ki_len;
u16 prf_len;
u16 block_len;
u16 conf_len;
u16 cksum_len;
...
};
encoding type 필드와 조회
80-105API 사용자가 주목해야 할 필드는 다음과 같습니다.
- `etype`과 `ctype`은 각각 encryption과 checksum 계산에 쓰는 이 encoding type의 protocol 번호를 나타냅니다. 값으로 `KRB5_ENCTYPE_*` 및 `KRB5_CKSUMTYPE_*` 상수를 담습니다.
- `name`은 encoding의 공식 이름입니다.
- `key_len`과 `key_bytes`는 각각 입력 key 길이와 유도된 key 길이입니다. 둘은 여기서 지원하지 않는 DES에서만 다른 것으로 보입니다.
- `Kc_len`, `Ke_len`, `Ki_len`은 유도된 Kc, Ke, Ki key의 크기입니다. Kc는 checksum mode에서 사용하고 Ke와 Ki는 encryption mode에서 사용합니다.
- `prf_len`은 PRF+ 함수 계산 결과의 크기입니다.
- `block_len`, `conf_len`, `cksum_len`은 각각 encryption block 길이, confounder 길이, checksum 길이입니다. 세 값 모두 encryption mode에서 사용하지만 checksum mode에서는 checksum 길이만 사용합니다.
encoding type은 다음 함수로 번호를 이용해 조회합니다.
const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype);
key derivation과 PRF+ 계산
106-127key derivation
application이 encryption type을 선택하면 실제 crypto에 사용할 key를 transport key로부터 유도할 수 있습니다.
PRF+ 계산
key derivation을 돕기 위해 Kerberos GSSAPI mechanism의 PRF+를 계산하는 함수를 제공합니다.
int crypto_krb5_calc_PRFplus(const struct krb5_enctype *krb5,
const struct krb5_buffer *K,
unsigned int L,
const struct krb5_buffer *S,
struct krb5_buffer *result,
gfp_t gfp);
이 함수는 source key와 그 용도를 제한하는 추가 데이터로부터 transport key를 유도하는 데 사용할 수 있습니다.
crypto 함수와 message buffer 배치
128-150crypto 함수
key를 유도한 뒤에는 데이터에 crypto 연산을 수행할 수 있습니다. 전송할 message를 준비할 때 caller는 confounder가 필요하다면 이를 저장할 공간과 checksum을 저장할 공간을 buffer에 비워 두어야 합니다. 이를 돕는 enum과 함수 두 개를 제공합니다.
enum krb5_crypto_mode {
KRB5_CHECKSUM_MODE,
KRB5_ENCRYPT_MODE,
};
size_t crypto_krb5_how_much_buffer(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t data_size, size_t *_offset);
size_t crypto_krb5_how_much_data(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t *_buffer_size, size_t *_offset);
이 함수들은 모두 encoding type과 crypto mode가 checksum 전용인지 full encryption인지 나타내는 값을 받습니다.
buffer 크기와 data 위치 확인
151-177첫 번째 함수는 주어진 양의 데이터를 담는 데 필요한 buffer 크기를 반환합니다. 두 번째 함수는 특정 크기의 buffer에 들어갈 데이터 양을 반환하고 필요한 buffer 크기를 그에 맞게 줄여 조정합니다. 두 경우 모두 buffer 안에서 데이터가 시작되는 offset도 반환합니다.
message를 수신한 뒤에는 다음 함수를 호출해 message 안의 데이터 위치와 크기를 판별할 수 있습니다.
int crypto_krb5_where_is_the_data(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t *_offset, size_t *_len);
caller는 message의 offset과 길이를 함수에 제공하며, 함수는 이 값을 데이터와 padding이 들어 있는 영역을 나타내도록 변경합니다. padding 양은 caller가 판별해야 합니다. 길이가 너무 짧거나 mode를 지원하지 않으면 함수가 error를 반환합니다. 다음 추가 함수도 제공합니다.
int crypto_krb5_check_data_len(const struct krb5_enctype *krb5,
enum krb5_crypto_mode mode,
size_t len, size_t min_content);
이 함수는 decrypted 또는 verified message가 충분한 최소 payload를 포함하는지만 기본적으로 검사합니다.
crypto 객체 준비 함수
178-198준비 함수
action 함수에서 사용할 crypto 객체를 할당하고 준비하는 함수 두 개를 제공합니다.
struct crypto_aead *
crypto_krb5_prepare_encryption(const struct krb5_enctype *krb5,
const struct krb5_buffer *TK,
u32 usage, gfp_t gfp);
struct crypto_shash *
crypto_krb5_prepare_checksum(const struct krb5_enctype *krb5,
const struct krb5_buffer *TK,
u32 usage, gfp_t gfp);
두 함수 모두 encoding type, transport key, 적절한 subkey를 유도하는 데 쓰는 usage 값을 받습니다. 함수는 encryption용 AEAD template 또는 checksum 계산용 synchronous hash에 해당하는 crypto 객체를 만들고, key를 설정한 뒤 객체를 구성합니다. caller는 반환된 handle을 아래 action 함수에 전달해야 합니다.
encryption mode API
199-216encryption mode
message를 encrypt하고 decrypt하는 함수 한 쌍을 제공합니다.
ssize_t crypto_krb5_encrypt(const struct krb5_enctype *krb5,
struct crypto_aead *aead,
struct scatterlist *sg, unsigned int nr_sg,
size_t sg_len,
size_t data_offset, size_t data_len,
bool preconfounded);
int crypto_krb5_decrypt(const struct krb5_enctype *krb5,
struct crypto_aead *aead,
struct scatterlist *sg, unsigned int nr_sg,
size_t *_offset, size_t *_len);
두 경우 모두 같은 scatterlist로 입력 buffer와 출력 buffer를 지정합니다.
encryption과 decryption 동작
217-226encryption 함수에서는 출력 buffer가 필요한 것보다 클 수 있으며 생성된 출력의 양이 반환됩니다. 데이터의 위치와 크기도 지정해야 하고 이는 encoding과 일치해야 합니다. confounder가 설정되지 않았다면 함수가 하나를 삽입합니다.
decryption 함수에는 buffer 안 message의 offset과 길이를 제공하며, 함수는 이 값을 실제 데이터에 맞게 줄입니다. decryption 함수는 message 안의 checksum도 검증하고 일치하지 않으면 error를 반환합니다.
checksum mode API
227-247checksum mode
message의 checksum을 생성하고 그 checksum을 검증하는 함수 한 쌍을 제공합니다.
ssize_t crypto_krb5_get_mic(const struct krb5_enctype *krb5,
struct crypto_shash *shash,
const struct krb5_buffer *metadata,
struct scatterlist *sg, unsigned int nr_sg,
size_t sg_len,
size_t data_offset, size_t data_len);
int crypto_krb5_verify_mic(const struct krb5_enctype *krb5,
struct crypto_shash *shash,
const struct krb5_buffer *metadata,
struct scatterlist *sg, unsigned int nr_sg,
size_t *_offset, size_t *_len);
두 경우 모두 같은 scatterlist로 입력 buffer와 출력 buffer를 지정합니다. 추가 metadata를 전달할 수 있으며, 이는 데이터보다 먼저 hash에 추가됩니다.
checksum 생성과 검증 동작
248-256`get_mic` 함수에서는 출력 buffer가 필요한 것보다 클 수 있으며 생성된 출력의 양이 반환됩니다. 데이터의 위치와 크기도 지정해야 하고 이는 encoding과 일치해야 합니다.
검증 함수에는 buffer 안 message의 offset과 길이를 제공하며, 함수는 이 값을 데이터에 맞게 줄입니다. checksum이 일치하지 않으면 error를 반환합니다.
krb5enc AEAD 알고리즘
257-271`krb5enc` AEAD 알고리즘
"krb5enc"라는 template AEAD crypto 알고리즘을 제공합니다. 이 알고리즘은 plaintext를 hash한 다음 encrypt하며, 이는 authenc와 반대 순서입니다. `crypto_krb5_prepare_encryption()`이 반환하는 handle이 이 유형일 수 있지만, 이 API의 사용자가 직접 상호 작용해야 할 필요는 없습니다.
참고로 key format은 format 번호의 BE32로 시작합니다. 제공되는 것은 format 1뿐이며, 이어서 Ke key 길이의 BE32, Ki key 길이의 BE32, Ke key byte, Ki key byte 순서로 구성됩니다.
특정 순서로 정렬된 word를 사용하므로 static test data에는 byteswapping이 필요하지 않습니다.
요약과 해설
krb5.rst:1-271이 문서는 network filesystem과 GSSAPI 구현이 Kerberos 5 암호 기능을 사용할 때 필요한 kernel API를 다룹니다. 지원 enctype와 checksum type, `krb5_enctype`의 길이 필드, PRF+ 기반 key derivation을 먼저 정의합니다.
실제 message 처리는 mode별 buffer 크기와 data offset을 계산하고, transport key와 usage 값으로 AEAD 또는 shash 객체를 준비한 뒤 encrypt/decrypt 또는 MIC 생성/검증 함수를 호출하는 흐름입니다. `krb5enc`는 plaintext를 먼저 hash하고 encrypt하는 전용 AEAD template입니다.