요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
=============================
Scatterlist Cryptographic API
=============================
Introduction
============
The Scatterlist Crypto API takes page vectors (scatterlists) as
arguments, and works directly on pages. In some cases (e.g. ECB
mode ciphers), this will allow for pages to be encrypted in-place
with no copying.
One of the initial goals of this design was to readily support IPsec,
so that processing can be applied to paged skb's without the need
for linearization.
Details
=======
At the lowest level are algorithms, which register dynamically with the
API.
'Transforms' are user-instantiated objects, which maintain state, handle all
of the implementation logic (e.g. manipulating page vectors) and provide an
abstraction to the underlying algorithms. However, at the user
level they are very simple.
Conceptually, the API layering looks like this::
[transform api] (user interface)
[transform ops] (per-type logic glue e.g. cipher.c, compress.c)
[algorithm api] (for registering algorithms)
The idea is to make the user interface and algorithm registration API
very simple, while hiding the core logic from both. Many good ideas
from existing APIs such as Cryptoapi and Nettle have been adapted for this.
The API currently supports five main types of transforms: AEAD (Authenticated
Encryption with Associated Data), Block Ciphers, Ciphers, Compressors and
Hashes.
Please note that Block Ciphers is somewhat of a misnomer. It is in fact
meant to support all ciphers including stream ciphers. The difference
between Block Ciphers and Ciphers is that the latter operates on exactly
one block while the former can operate on an arbitrary amount of data,
subject to block size requirements (i.e., non-stream ciphers can only
process multiples of blocks).
Here's an example of how to use the API::
#include <crypto/hash.h>
#include <linux/err.h>
#include <linux/scatterlist.h>
struct scatterlist sg[2];
char result[128];
struct crypto_ahash *tfm;
struct ahash_request *req;
tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm))
fail();
/* ... set up the scatterlists ... */
req = ahash_request_alloc(tfm, GFP_ATOMIC);
if (!req)
fail();
ahash_request_set_callback(req, 0, NULL, NULL);
ahash_request_set_crypt(req, sg, result, 2);
if (crypto_ahash_digest(req))
fail();
ahash_request_free(req);
crypto_free_ahash(tfm);
Many real examples are available in the regression test module (tcrypt.c).
Developer Notes
===============
Transforms may only be allocated in user context, and cryptographic
methods may only be called from softirq and user contexts. For
transforms with a setkey method it too should only be called from
user context.
When using the API for ciphers, performance will be optimal if each
scatterlist contains data which is a multiple of the cipher's block
size (typically 8 bytes). This prevents having to do any copying
across non-aligned page fragment boundaries.
Adding New Algorithms
=====================
When submitting a new algorithm for inclusion, a mandatory requirement
is that at least a few test vectors from known sources (preferably
standards) be included.
Converting existing well known code is preferred, as it is more likely
to have been reviewed and widely tested. If submitting code from LGPL
sources, please consider changing the license to GPL (see section 3 of
the LGPL).
Algorithms submitted must also be generally patent-free (e.g. IDEA
will not be included in the mainline until around 2011), and be based
on a recognized standard and/or have been subjected to appropriate
peer review.
Also check for any RFCs which may relate to the use of specific algorithms,
as well as general application notes such as RFC2451 ("The ESP CBC-Mode
Cipher Algorithms").
It's a good idea to avoid using lots of macros and use inlined functions
instead, as gcc does a good job with inlining, while excessive use of
macros can cause compilation problems on some platforms.
Also check the TODO list at the web site listed below to see what people
might already be working on.
Bugs
====
Send bug reports to:
Cc:
Herbert Xu <[email protected]>,
David S. Miller <[email protected]>
Further Information
===================
For further patches and various updates, including the current TODO
list, see:
http://gondor.apana.org.au/~herbert/crypto/
Authors
=======
- James Morris
- David S. Miller
- Herbert Xu
Credits
=======
The following people provided invaluable feedback during the development
of the API:
- Alexey Kuznetzov
- Rusty Russell
- Herbert Valerio Riedel
- Jeff Garzik
- Michael Richardson
- Andrew Morton
- Ingo Oeser
- Christoph Hellwig
Portions of this API were derived from the following projects:
Kerneli Cryptoapi (http://www.kerneli.org/)
- Alexander Kjeldaas
- Herbert Valerio Riedel
- Kyle McMartin
- Jean-Luc Cooke
- David Bryson
- Clemens Fruhwirth
- Tobias Ringstrom
- Harald Welte
and;
Nettle (https://www.lysator.liu.se/~nisse/nettle/)
- Niels Möller
Original developers of the crypto algorithms:
- Dana L. How (DES)
- Andrew Tridgell and Steve French (MD4)
- Colin Plumb (MD5)
- Steve Reid (SHA1)
- Jean-Luc Cooke (SHA256, SHA384, SHA512)
- Kazunori Miyazawa / USAGI (HMAC)
- Matthew Skala (Twofish)
- Dag Arne Osvik (Serpent)
- Brian Gladman (AES)
- Kartikey Mahendra Bhatt (CAST6)
- Jon Oberheide (ARC4)
- Jouni Malinen (Michael MIC)
- NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
SHA1 algorithm contributors:
- Jean-Francois Dive
DES algorithm contributors:
- Raimar Falke
- Gisle Sælensminde
- Niels Möller
Blowfish algorithm contributors:
- Herbert Valerio Riedel
- Kyle McMartin
Twofish algorithm contributors:
- Werner Koch
- Marc Mutz
SHA256/384/512 algorithm contributors:
- Andrew McDonald
- Kyle McMartin
- Herbert Valerio Riedel
AES algorithm contributors:
- Alexander Kjeldaas
- Herbert Valerio Riedel
- Kyle McMartin
- Adam J. Richter
- Fruhwirth Clemens (i586)
- Linus Torvalds (i586)
CAST5 algorithm contributors:
- Kartikey Mahendra Bhatt (original developers unknown, FSF copyright).
TEA/XTEA algorithm contributors:
- Aaron Grothe
- Michael Ringe
Khazad algorithm contributors:
- Aaron Grothe
Whirlpool algorithm contributors:
- Aaron Grothe
- Jean-Luc Cooke
Anubis algorithm contributors:
- Aaron Grothe
Tiger algorithm contributors:
- Aaron Grothe
VIA PadLock contributors:
- Michal Ludvig
Camellia algorithm contributors:
- NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
Generic scatterwalk code by Adam J. Richter <[email protected]>
Please send any credits updates or corrections to:
Herbert Xu <[email protected]>
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
Scatterlist Cryptographic API
1-19.. SPDX-License-Identifier: GPL-2.0
Scatterlist Cryptographic API
소개
Scatterlist Crypto API는 page vector인 scatterlist를 argument로 받아 page에서 직접 동작합니다. ECB mode cipher 같은 일부 경우에는 복사 없이 page를 in-place로 encrypt할 수 있습니다.
이 설계의 초기 목표 중 하나는 IPsec을 쉽게 지원하여 paged skb를 linearization하지 않고도 처리할 수 있게 하는 것이었습니다.
상세 구조와 사용 예제
20-85상세
가장 낮은 level에는 API에 동적으로 등록되는 algorithm이 있습니다.
`Transform`은 사용자가 instance화한 object로서 state를 유지하고 page vector 조작 같은 구현 logic을 모두 처리하며 underlying algorithm을 추상화합니다. 하지만 사용자 level에서는 매우 단순합니다.
개념적인 API layering은 다음과 같습니다.
[transform api] (user interface)
[transform ops] (per-type logic glue e.g. cipher.c, compress.c)
[algorithm api] (for registering algorithms)
사용자 interface에서 type별 logic glue를 거쳐 algorithm registration layer로 내려가는 구조입니다.
사용자 interface와 algorithm registration API를 매우 단순하게 유지하면서 core logic을 양쪽에서 숨기는 것이 목표입니다. Cryptoapi와 Nettle 같은 기존 API의 좋은 아이디어를 많이 적용했습니다.
현재 API는 AEAD(Authenticated Encryption with Associated Data), Block Cipher, Cipher, Compressor, Hash의 다섯 가지 주요 transform type을 지원합니다.
Block Cipher라는 이름은 다소 부정확합니다. 실제로는 stream cipher를 포함한 모든 cipher를 지원하도록 설계되었습니다. Block Cipher와 Cipher의 차이는 후자가 정확히 block 하나에 동작하는 반면, 전자는 block size 요구사항 안에서 임의 양의 data를 처리할 수 있다는 점입니다. 즉 non-stream cipher는 block의 배수만 처리할 수 있습니다.
API 사용 예제:
#include <crypto/hash.h>
#include <linux/err.h>
#include <linux/scatterlist.h>
struct scatterlist sg[2];
char result[128];
struct crypto_ahash *tfm;
struct ahash_request *req;
tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC);
if (IS_ERR(tfm))
fail();
/* ... set up the scatterlists ... */
req = ahash_request_alloc(tfm, GFP_ATOMIC);
if (!req)
fail();
ahash_request_set_callback(req, 0, NULL, NULL);
ahash_request_set_crypt(req, sg, result, 2);
if (crypto_ahash_digest(req))
fail();
ahash_request_free(req);
crypto_free_ahash(tfm);
실제 예제는 regression test module인 `tcrypt.c`에서 많이 찾을 수 있습니다.
개발자 참고 사항
86-99개발자 참고 사항
Transform은 user context에서만 할당할 수 있고 cryptographic method는 softirq와 user context에서만 호출할 수 있습니다. `setkey` method가 있는 transform의 해당 method도 user context에서만 호출해야 합니다.
Cipher API를 사용할 때 각 scatterlist가 cipher block size, 보통 8 byte의 배수인 data를 포함하면 성능이 최적입니다. 그러면 alignment가 맞지 않는 page fragment boundary를 가로질러 복사할 필요가 없습니다.
새 algorithm 추가
100-128새 algorithm 추가
새 algorithm을 inclusion 대상으로 제출할 때는 알려진 출처, 가능하면 standard에서 가져온 test vector를 최소 몇 개 포함해야 합니다. 이는 필수 요구사항입니다.
기존의 잘 알려진 code를 변환하는 방식을 선호합니다. 이미 review되고 널리 test되었을 가능성이 높기 때문입니다. LGPL source의 code를 제출한다면 LGPL section 3을 참고하여 license를 GPL로 변경하는 것을 고려하십시오.
제출하는 algorithm은 일반적으로 patent-free여야 하며, 인정된 standard를 기반으로 하거나 적절한 peer review를 거쳐야 합니다. 원문은 IDEA가 약 2011년까지 mainline에 포함되지 않을 사례를 듭니다.
특정 algorithm 사용과 관련된 RFC뿐 아니라 RFC2451 `The ESP CBC-Mode Cipher Algorithms` 같은 일반 application note도 확인하십시오.
많은 macro를 사용하기보다 inline function을 사용하는 편이 좋습니다. GCC는 inlining을 잘 수행하지만 macro를 지나치게 사용하면 일부 platform에서 compilation 문제가 생길 수 있습니다.
아래 web site의 TODO list도 확인하여 다른 사람이 이미 작업 중인 항목이 있는지 살펴보십시오.
Bug 보고
129-139Bug 보고
Bug report는 `[email protected]`로 보내십시오.
Cc: Herbert Xu <[email protected]>, David S. Miller <[email protected]>
추가 정보
140-147추가 정보
현재 TODO list를 포함한 patch와 여러 update는 다음 위치를 참조하십시오.
저자
148-155저자
- James Morris
- David S. Miller
- Herbert Xu
API 개발 feedback
156-170크레딧
다음 사람들은 API 개발 과정에서 매우 중요한 feedback을 제공했습니다.
- Alexey Kuznetzov
- Rusty Russell
- Herbert Valerio Riedel
- Jeff Garzik
- Michael Richardson
- Andrew Morton
- Ingo Oeser
- Christoph Hellwig
기반 project
171-187이 API의 일부는 다음 project에서 유래했습니다.
Kerneli Cryptoapi 기여자:
- Alexander Kjeldaas
- Herbert Valerio Riedel
- Kyle McMartin
- Jean-Luc Cooke
- David Bryson
- Clemens Fruhwirth
- Tobias Ringstrom
- Harald Welte
Nettle 기여자:
- Niels Möller
Crypto algorithm 원 개발자
188-203Crypto algorithm의 원 개발자:
- Dana L. How (DES)
- Andrew Tridgell and Steve French (MD4)
- Colin Plumb (MD5)
- Steve Reid (SHA1)
- Jean-Luc Cooke (SHA256, SHA384, SHA512)
- Kazunori Miyazawa / USAGI (HMAC)
- Matthew Skala (Twofish)
- Dag Arne Osvik (Serpent)
- Brian Gladman (AES)
- Kartikey Mahendra Bhatt (CAST6)
- Jon Oberheide (ARC4)
- Jouni Malinen (Michael MIC)
- NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
Algorithm별 기여자
204-258SHA1 algorithm 기여자:
- Jean-Francois Dive
DES algorithm 기여자:
- Raimar Falke
- Gisle Sælensminde
- Niels Möller
Blowfish algorithm 기여자:
- Herbert Valerio Riedel
- Kyle McMartin
Twofish algorithm 기여자:
- Werner Koch
- Marc Mutz
SHA256/384/512 algorithm 기여자:
- Andrew McDonald
- Kyle McMartin
- Herbert Valerio Riedel
AES algorithm 기여자:
- Alexander Kjeldaas
- Herbert Valerio Riedel
- Kyle McMartin
- Adam J. Richter
- Fruhwirth Clemens (i586)
- Linus Torvalds (i586)
CAST5 algorithm 기여자:
- Kartikey Mahendra Bhatt (original developers unknown, FSF copyright)
TEA/XTEA algorithm 기여자:
- Aaron Grothe
- Michael Ringe
Khazad algorithm 기여자:
- Aaron Grothe
Whirlpool algorithm 기여자:
- Aaron Grothe
- Jean-Luc Cooke
Anubis algorithm 기여자:
- Aaron Grothe
Tiger algorithm 기여자:
- Aaron Grothe
VIA PadLock 기여자:
- Michal Ludvig
Camellia algorithm 기여자:
- NTT(Nippon Telegraph and Telephone Corporation) (Camellia)
추가 credit 연락처
259-262Generic scatterwalk code는 Adam J. Richter <[email protected]>가 작성했습니다.
Credit update나 correction은 Herbert Xu <[email protected]>에게 보내십시오.
요약과 해설
api-intro.rst:1-262Scatterlist Crypto API는 page vector를 직접 처리하여 불필요한 linearization과 copy를 줄입니다. Transform layer가 state와 per-type logic을 감추고 algorithm layer가 구현 등록을 담당합니다.
Transform 할당과 `setkey`는 user context에서 수행하고 cryptographic method는 user 또는 softirq context에서 호출해야 합니다. Scatterlist segment를 block size 배수로 맞추면 fragment boundary copy를 피할 수 있습니다.
새 algorithm은 신뢰할 수 있는 test vector, recognized standard 또는 peer review, patent 검토가 필요합니다. 기존의 검증된 code를 활용하고 macro보다 inline function을 선호합니다.
문서 후반부는 API가 Cryptoapi와 Nettle에서 이어받은 부분, algorithm 원 개발자와 subsystem 기여자를 원문 순서대로 기록합니다.