← Documents Documentation/crypto/krb5.rst GitHub 원문 ↗

Linux 6.18.37 · Crypto

Kerberos V Cryptography API

Kerberos 5 방식의 key derivation, encryption, checksum API와 buffer 배치, crypto 객체 준비, krb5enc AEAD 형식을 설명합니다.

Source pathDocumentation/crypto/krb5.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

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입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===========================
4 Kerberos V Cryptography API
5 ===========================
6
7 .. Contents:
8
9 - Overview.
10 - Small Buffer.
11 - Encoding Type.
12 - Key Derivation.
13 - PRF+ Calculation.
14 - Kc, Ke And Ki Derivation.
15 - Crypto Functions.
16 - Preparation Functions.
17 - Encryption Mode.
18 - Checksum Mode.
19 - The krb5enc AEAD algorithm
20
21 Overview
22 ========
23
24 This API provides Kerberos 5-style cryptography for key derivation, encryption
25 and checksumming for use in network filesystems and can be used to implement
26 the low-level crypto that's needed for GSSAPI.
27
28 The following crypto types are supported::
29
30 KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96
31 KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96
32 KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128
33 KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192
34 KRB5_ENCTYPE_CAMELLIA128_CTS_CMAC
35 KRB5_ENCTYPE_CAMELLIA256_CTS_CMAC
36
37 KRB5_CKSUMTYPE_HMAC_SHA1_96_AES128
38 KRB5_CKSUMTYPE_HMAC_SHA1_96_AES256
39 KRB5_CKSUMTYPE_CMAC_CAMELLIA128
40 KRB5_CKSUMTYPE_CMAC_CAMELLIA256
41 KRB5_CKSUMTYPE_HMAC_SHA256_128_AES128
42 KRB5_CKSUMTYPE_HMAC_SHA384_192_AES256
43
44 The API can be included by::
45
46 #include <crypto/krb5.h>
47
48 Small Buffer
49 ------------
50
51 To pass small pieces of data about, such as keys, a buffer structure is
52 defined, giving a pointer to the data and the size of that data::
53
54 struct krb5_buffer {
55 unsigned int len;
56 void *data;
57 };
58
59 Encoding Type
60 =============
61
62 The encoding type is defined by the following structure::
63
64 struct krb5_enctype {
65 int etype;
66 int ctype;
67 const char *name;
68 u16 key_bytes;
69 u16 key_len;
70 u16 Kc_len;
71 u16 Ke_len;
72 u16 Ki_len;
73 u16 prf_len;
74 u16 block_len;
75 u16 conf_len;
76 u16 cksum_len;
77 ...
78 };
79
80 The fields of interest to the user of the API are as follows:
81
82 * ``etype`` and ``ctype`` indicate the protocol number for this encoding
83 type for encryption and checksumming respectively. They hold
84 ``KRB5_ENCTYPE_*`` and ``KRB5_CKSUMTYPE_*`` constants.
85
86 * ``name`` is the formal name of the encoding.
87
88 * ``key_len`` and ``key_bytes`` are the input key length and the derived key
89 length. (I think they only differ for DES, which isn't supported here).
90
91 * ``Kc_len``, ``Ke_len`` and ``Ki_len`` are the sizes of the derived Kc, Ke
92 and Ki keys. Kc is used for in checksum mode; Ke and Ki are used in
93 encryption mode.
94
95 * ``prf_len`` is the size of the result from the PRF+ function calculation.
96
97 * ``block_len``, ``conf_len`` and ``cksum_len`` are the encryption block
98 length, confounder length and checksum length respectively. All three are
99 used in encryption mode, but only the checksum length is used in checksum
100 mode.
101
102 The encoding type is looked up by number using the following function::
103
104 const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype);
105
106 Key Derivation
107 ==============
108
109 Once the application has selected an encryption type, the keys that will be
110 used to do the actual crypto can be derived from the transport key.
111
112 PRF+ Calculation
113 ----------------
114
115 To aid in key derivation, a function to calculate the Kerberos GSSAPI
116 mechanism's PRF+ is provided::
117
118 int crypto_krb5_calc_PRFplus(const struct krb5_enctype *krb5,
119 const struct krb5_buffer *K,
120 unsigned int L,
121 const struct krb5_buffer *S,
122 struct krb5_buffer *result,
123 gfp_t gfp);
124
125 This can be used to derive the transport key from a source key plus additional
126 data to limit its use.
127
128 Crypto Functions
129 ================
130
131 Once the keys have been derived, crypto can be performed on the data. The
132 caller must leave gaps in the buffer for the storage of the confounder (if
133 needed) and the checksum when preparing a message for transmission. An enum
134 and a pair of functions are provided to aid in this::
135
136 enum krb5_crypto_mode {
137 KRB5_CHECKSUM_MODE,
138 KRB5_ENCRYPT_MODE,
139 };
140
141 size_t crypto_krb5_how_much_buffer(const struct krb5_enctype *krb5,
142 enum krb5_crypto_mode mode,
143 size_t data_size, size_t *_offset);
144
145 size_t crypto_krb5_how_much_data(const struct krb5_enctype *krb5,
146 enum krb5_crypto_mode mode,
147 size_t *_buffer_size, size_t *_offset);
148
149 All these functions take the encoding type and an indication the mode of crypto
150 (checksum-only or full encryption).
151
152 The first function returns how big the buffer will need to be to house a given
153 amount of data; the second function returns how much data will fit in a buffer
154 of a particular size, and adjusts down the size of the required buffer
155 accordingly. In both cases, the offset of the data within the buffer is also
156 returned.
157
158 When a message has been received, the location and size of the data with the
159 message can be determined by calling::
160
161 int crypto_krb5_where_is_the_data(const struct krb5_enctype *krb5,
162 enum krb5_crypto_mode mode,
163 size_t *_offset, size_t *_len);
164
165 The caller provides the offset and length of the message to the function, which
166 then alters those values to indicate the region containing the data (plus any
167 padding). It is up to the caller to determine how much padding there is. The
168 function returns an error if the length is too small or if the mode is
169 unsupported. An additional function::
170
171 int crypto_krb5_check_data_len(const struct krb5_enctype *krb5,
172 enum krb5_crypto_mode mode,
173 size_t len, size_t min_content);
174
175 is provided to just do a basic check that the decrypted/verified message would
176 have a sufficient minimum payload.
177
178 Preparation Functions
179 ---------------------
180
181 Two functions are provided to allocated and prepare a crypto object for use by
182 the action functions::
183
184 struct crypto_aead *
185 crypto_krb5_prepare_encryption(const struct krb5_enctype *krb5,
186 const struct krb5_buffer *TK,
187 u32 usage, gfp_t gfp);
188 struct crypto_shash *
189 crypto_krb5_prepare_checksum(const struct krb5_enctype *krb5,
190 const struct krb5_buffer *TK,
191 u32 usage, gfp_t gfp);
192
193 Both of these functions take the encoding type, the transport key and the usage
194 value used to derive the appropriate subkey(s). They create an appropriate
195 crypto object, an AEAD template for encryption and a synchronous hash for
196 checksumming, set the key(s) on it and configure it. The caller is expected to
197 pass these handles to the action functions below.
198
199 Encryption Mode
200 ---------------
201
202 A pair of functions are provided to encrypt and decrypt a message::
203
204 ssize_t crypto_krb5_encrypt(const struct krb5_enctype *krb5,
205 struct crypto_aead *aead,
206 struct scatterlist *sg, unsigned int nr_sg,
207 size_t sg_len,
208 size_t data_offset, size_t data_len,
209 bool preconfounded);
210 int crypto_krb5_decrypt(const struct krb5_enctype *krb5,
211 struct crypto_aead *aead,
212 struct scatterlist *sg, unsigned int nr_sg,
213 size_t *_offset, size_t *_len);
214
215 In both cases, the input and output buffers are indicated by the same
216 scatterlist.
217
218 For the encryption function, the output buffer may be larger than is needed
219 (the amount of output generated is returned) and the location and size of the
220 data are indicated (which must match the encoding). If no confounder is set,
221 the function will insert one.
222
223 For the decryption function, the offset and length of the message in buffer are
224 supplied and these are shrunk to fit the data. The decryption function will
225 verify any checksums within the message and give an error if they don't match.
226
227 Checksum Mode
228 -------------
229
230 A pair of function are provided to generate the checksum on a message and to
231 verify that checksum::
232
233 ssize_t crypto_krb5_get_mic(const struct krb5_enctype *krb5,
234 struct crypto_shash *shash,
235 const struct krb5_buffer *metadata,
236 struct scatterlist *sg, unsigned int nr_sg,
237 size_t sg_len,
238 size_t data_offset, size_t data_len);
239 int crypto_krb5_verify_mic(const struct krb5_enctype *krb5,
240 struct crypto_shash *shash,
241 const struct krb5_buffer *metadata,
242 struct scatterlist *sg, unsigned int nr_sg,
243 size_t *_offset, size_t *_len);
244
245 In both cases, the input and output buffers are indicated by the same
246 scatterlist. Additional metadata can be passed in which will get added to the
247 hash before the data.
248
249 For the get_mic function, the output buffer may be larger than is needed (the
250 amount of output generated is returned) and the location and size of the data
251 are indicated (which must match the encoding).
252
253 For the verification function, the offset and length of the message in buffer
254 are supplied and these are shrunk to fit the data. An error will be returned
255 if the checksums don't match.
256
257 The krb5enc AEAD algorithm
258 ==========================
259
260 A template AEAD crypto algorithm, called "krb5enc", is provided that hashes the
261 plaintext before encrypting it (the reverse of authenc). The handle returned
262 by ``crypto_krb5_prepare_encryption()`` may be one of these, but there's no
263 requirement for the user of this API to interact with it directly.
264
265 For reference, its key format begins with a BE32 of the format number. Only
266 format 1 is provided and that continues with a BE32 of the Ke key length
267 followed by a BE32 of the Ki key length, followed by the bytes from the Ke key
268 and then the Ki key.
269
270 Using specifically ordered words means that the static test data doesn't
271 require byteswapping.
272

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Kerberos V Cryptography API와 목차

1-20

SPDX 라이선스 식별자: 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-79

encoding 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-105

API 사용자가 주목해야 할 필드는 다음과 같습니다.

  • `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-127

key 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-150

crypto 함수

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-216

encryption 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-226

encryption 함수에서는 출력 buffer가 필요한 것보다 클 수 있으며 생성된 출력의 양이 반환됩니다. 데이터의 위치와 크기도 지정해야 하고 이는 encoding과 일치해야 합니다. confounder가 설정되지 않았다면 함수가 하나를 삽입합니다.

decryption 함수에는 buffer 안 message의 offset과 길이를 제공하며, 함수는 이 값을 실제 데이터에 맞게 줄입니다. decryption 함수는 message 안의 checksum도 검증하고 일치하지 않으면 error를 반환합니다.

checksum mode API

227-247

checksum 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이 필요하지 않습니다.