]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - README.gost
Private key format configure by openssl.cnf file
[openssl-gost/engine.git] / README.gost
1 GOST ENGINE
2
3 This engine provides implementation of Russian cryptography standard.
4 This is also an example of adding new cryptoalgorithms into OpenSSL
5 without changing its core. If OpenSSL is compiled with dynamic engine
6 support, new algorithms can be added even without recompilation of
7 OpenSSL and applications which use it.
8
9 ALGORITHMS SUPPORTED
10
11 GOST R 34.10-2001 and GOST R 34.10-2012 - digital signature algorithms.
12    Also support key exchange based on public keys. See RFC 4357 for
13    details of VKO key exchange algorithm. These algorithms use
14    256 bit private keys. Public keys are 1024 bit for 94 and 512 bit for
15    2001 (which is elliptic-curve based). Key exchange algorithms
16    (VKO R 34.10) are supported on these keys too.
17    
18 GOST R 34.11-2012  Message digest algorithm. 256- and 512-bit hash values.
19
20 GOST 28147-89 - Symmetric cipher  with 256-bit key. Various modes are
21    defined in the standard, but only CFB and CNT modes are implemented
22    in the engine. To make statistical analysis more difficult, key
23    meshing is supported (see RFC 4357).
24
25 GOST 28147-89 MAC mode. Message authentication code. While most MAC
26     algorithms  out there are based on hash functions using HMAC
27         algorithm, this algoritm is based on symmetric cipher. 
28         It has 256-bit symmetric key and only 32 bits of MAC value
29         (while HMAC has same key size and value size). 
30
31         Really, this algorithm supports from 8 to 64 bits of the MAC value
32
33         It is implemented as combination of EVP_PKEY type and EVP_MD type.
34
35 GOST R 34.13–2015 - Symmetric cypher Grasshopper ("Kuznechik")
36
37 USAGE OF THESE ALGORITHMS
38
39 This engine is designed to allow usage of this algorithms in the
40 high-level openssl functions, such as PKI, S/MIME and TLS.
41
42 See RFC 4490 for S/MIME with GOST algorithms and RFC 4491 for PKI.
43 TLS support is implemented according IETF
44 draft-chudov-cryptopro-cptls-03.txt and is compatible with
45 CryptoPro CSP 3.0 and 3.6 as well as with MagPro CSP. 
46 GOST ciphersuites implemented in CryptoPro CSP 2.0 are not supported
47 because they use ciphersuite numbers used now by AES ciphersuites.
48
49 To use the engine you have to load it via openssl configuration
50 file. Applications should read openssl configuration file or provide
51 their own means to load engines. Also, applications which operate with
52 private keys, should use generic EVP_PKEY API instead of using RSA or
53 other algorithm-specific API.
54
55 CONFIGURATION FILE
56
57 Configuration file should include following statement in the global
58 section, i.e. before first bracketed section header (see config(5) for details)
59
60    openssl_conf = openssl_def
61
62 where openssl_def is name of the section in configuration file which
63 describes global defaults.
64
65 This section should contain following statement:
66
67    [openssl_def]
68    engines = engine_section
69
70 which points to the section which describes list of the engines to be
71 loaded. This section should contain:
72
73         [engine_section]
74         gost = gost_section
75
76 And section which describes configuration of the engine should contain
77
78         [gost_section]
79         engine_id = gost
80         dynamic_path = /usr/lib/ssl/engines/libgost.so
81         default_algorithms = ALL
82         CRYPT_PARAMS = id-Gost28147-89-CryptoPro-A-ParamSet
83
84 If you want use unmask private key format, you must add:
85   PK_PARAMS = UNMASK
86 to [gost_section]
87
88 Where engine_id parameter specifies name of engine (should be "gost").
89 dynamic_path is a location of the loadable shared library implementing the
90 engine. If the engine is compiled statically or is located in the OpenSSL
91 engines directory, this line can be omitted. 
92 default_algorithms parameter specifies that all algorithms, provided by
93 engine, should be used.
94
95 The CRYPT_PARAMS parameter is engine-specific. It allows the user to choose
96 between different parameter sets of symmetric cipher algorithm. RFC 4357
97 specifies several parameters for the GOST 28147-89 algorithm, but OpenSSL
98 doesn't provide user interface to choose one when encrypting. So use engine
99 configuration parameter instead.
100
101 Value of this parameter can be either short name, defined in OpenSSL
102 obj_dat.h header file or numeric representation of OID, defined in RFC
103 4357. 
104
105 USAGE WITH COMMAND LINE openssl UTILITY
106
107 1. Generation of private key
108
109         openssl genpkey -algorithm gost2001 -pkeyopt paramset:A -out seckey.pem
110
111   Use -algorithm option to specify algorithm.
112   Use -pkeyopt option to pass paramset to algorithm. The following paramsets
113   are supported by 
114         gost94: 0,A,B,C,D,XA,XB,XC
115         gost2001: 0,A,B,C,XA,XB
116   You can also use numeric representation of OID as to destinate
117   paramset.
118
119   Paramsets starting with X are intended to use for key exchange keys.
120   Paramsets without X are for digital signature keys.
121
122   Paramset for both algorithms 0 is the test paramset which should be used
123   only for test purposes.
124
125 There are no algorithm-specific things with generation of certificate
126 request once you have a private key.
127
128 2. Generation of certificate request along with private/public keypar
129
130    openssl req -newkey gost2001 -pkeyopt paramset:A
131
132    Syntax of -pkeyopt parameter is identical with genpkey command.
133
134    You can also use oldstyle syntax -newkey gost2001:paramfile, but in
135    this case you should create parameter file first. 
136
137    It can be created with
138
139    openssl genpkey -genparam -algorithm gost2001 -pkeyopt paramset:A\
140       -out paramfile.
141
142 3. S/MIME operations
143
144 If you want to send encrypted mail using GOST algorithms, don't forget
145 to specify -gost89 as encryption algorithm for OpenSSL smime command.
146 While OpenSSL is clever enough to find out that GOST R 34.11-94 digest
147 must be used for digital signing with GOST private key, it have no way
148 to derive symmetric encryption algorithm from key exchange keys.
149
150 4. TLS operations
151
152 OpenSSL supports all four ciphersuites defined in the IETF draft.
153 Once you've loaded GOST key and certificate into your TLS server,
154 ciphersuites which use GOST 28147-89 encryption are enabled.
155
156 Ciphersuites with NULL encryption should be enabled explicitely if
157 needed.
158
159 GOST2001-GOST89-GOST89 Uses GOST R 34.10-2001 for auth and key exchange
160                 GOST 28147-89 for encryption and GOST 28147-89 MAC
161 GOST94-GOST89-GOST89 Uses GOST R 34.10-94 for auth and key exchange
162                 GOST 28147-89 for encryption and GOST 28147-89 MAC
163 GOST2001-NULL-GOST94 Uses GOST R 34.10-2001 for auth and key exchange,
164         no encryption and HMAC, based on GOST R 34.11-94
165 GOST94-NULL-GOST94 Uses GOST R 34.10-94 for auth and key exchange,
166         no encryption and HMAC, based on GOST R 34.11-94
167
168 Gost 94 and gost 2001 keys can be used simultaneously in the TLS server.
169 RSA, DSA and EC keys can be used simultaneously with GOST keys, if
170 server implementation supports loading more than two private
171 key/certificate pairs. In this case ciphersuites which use any of loaded
172 keys would be supported and clients can negotiate ones they wish.
173
174 This allows creation of TLS servers which use GOST ciphersuites for
175 Russian clients and RSA/DSA ciphersuites for foreign clients.
176
177 5. Calculation of digests and symmetric encryption
178  OpenSSL provides specific commands (like sha1, aes etc) for calculation
179  of digests and symmetric encryption. Since such commands cannot be
180  added dynamically, no such commands are provided for GOST algorithms.
181  Use generic commands 'dgst' and 'enc'.
182
183  Calculation of GOST R 34.11-94 message digest
184
185  openssl dgst -md_gost94 datafile
186
187  Note that GOST R 34.11-94 specifies that digest value should be
188  interpreted as little-endian number, but OpenSSL outputs just hex dump
189  of digest value.
190
191  So, to obtain correct digest value, such as produced by gostsum utility
192  included in the engine distribution, bytes of output should be
193  reversed.
194  
195  Calculation of HMAC based on GOST R 34.11-94
196
197  openssl dgst -md_gost94 -mac hmac -macopt key:<32 bytes of key> datafile
198   
199   (or use hexkey if key contain NUL bytes)
200  Calculation of GOST 28147 MAC
201
202  openssl dgst -mac gost-mac -macopt key:<32 bytes of key> datafile
203
204  Note absence of an option that specifies digest algorithm. gost-mac
205  algorithm supports only one digest (which is actually part of
206  implementation of this mac) and OpenSSL is clever enough to find out
207  this.
208
209  Following mac options are supported:
210
211  key:(32 bytes of key)
212
213  hexkey:(64 hexadecimal digits of key)
214
215  Engine support calculation of mac with size different from default 32
216  bits. You can set mac size to any value from 1 to 8 bytes using
217
218  -sigopt size:(number from 1 to 8 - mac size in bytes)
219
220  (dgst command uses different EVP_PKEY_CTX for initialization and for
221   finalization of MAC. Option of first are set via -macopt, and for
222   second via -sigopt. Key should be set during initialization and size
223   during finalization. If you use API functions
224   EVP_DigestSignInit/EVP_DigestSignFinal, you can set both options at
225   the same time).
226
227  Encryption with GOST 28147 CFB mode
228  openssl enc -gost89 -out encrypted-file -in plain-text-file -k <passphrase>  
229  Encryption with GOST 28147 CNT mode
230  openssl enc -gost89-cnt -out encrypted-file -in plain-text-file -k <passphrase>
231  Encryption with GOST 28147 CBC mode
232  openssl enc -gost89-cbc -out encrypted-file -in plain-text-file -k <passphrase>
233
234 6. Encrypting private keys and PKCS12
235
236 To produce PKCS12 files compatible with MagPro CSP, you need to use
237 GOST algorithm for encryption of PKCS12 file and also GOST R 34.11-94
238 hash to derive key from password.
239
240 openssl pksc12 -export -inkey gost.pem -in gost_cert.pem -keypbe gost89\
241    -certpbe gost89 -macalg md_gost94
242  
243 7. Testing speed of symmetric ciphers.
244    
245 To test performance of GOST symmetric ciphers you should use -evp switch
246 of the openssl speed command. Engine-provided ciphers couldn't be
247 accessed by cipher-specific functions, only via generic evp interface
248
249  openssl speed -evp gost89
250  openssl speed -evp gost89-cnt
251  openssl speed -evp gost89-cbc
252
253
254 PROGRAMMING INTERFACES DETAILS
255
256 Applications never should access engine directly. They only use provided
257 EVP_PKEY API. But there are some details, which should be taken into
258 account.
259
260 EVP provides two kinds of API for key exchange:
261
262 1. EVP_PKEY_encrypt/EVP_PKEY_decrypt functions, intended to use with
263         RSA-like public key encryption algorithms
264
265 2. EVP_PKEY_derive, intended to use with Diffie-Hellman-like shared key
266 computing algorithms.
267
268 Although VKO R 34.10 algorithms, described in the RFC 4357 are
269 definitely second case, engine provides BOTH API for GOST R 34.10 keys.
270
271 EVP_PKEY_derive just invokes appropriate VKO algorithm and computes
272 256 bit shared key. VKO R 34.10-2001 requires 64 bits of random user key
273 material (UKM). This UKM should be transmitted to other party, so it is
274 not generated inside derive function.
275
276 It should be set by EVP_PKEY_CTX_ctrl function using
277 EVP_PKEY_CTRL_SET_IV command after call of EVP_PKEY_derive_init, but
278 before EVP_PKEY_derive.
279         unsigned char ukm[8];
280         RAND_bytes(ukm,8);
281    EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, 8, ukm)
282
283 EVP_PKEY_encrypt encrypts provided session key with VKO shared key and
284 packs it into GOST key transport structure, described in the RFC 4490.
285
286 It typically uses ephemeral key pair to compute shared key and packs its
287 public part along with encrypted key. So, for most cases use of 
288 EVP_PKEY_encrypt/EVP_PKEY_decrypt with GOST keys is almost same as with
289 RSA.
290
291 However, if peerkey field in the EVP_PKEY_CTX structure is set (using
292 EVP_PKEY_derive_set_peerkey function) to EVP_PKEY structure which has private
293 key and uses same parameters as the public key from which this EVP_PKEY_CTX is
294 created, EVP_PKEY_encrypt will use this private key to compute shared key and
295 set ephemeral key in the GOST_key_transport structure to NULL. In this case
296 pkey and peerkey fields in the EVP_PKEY_CTX are used upside-down.
297
298 If EVP_PKEY_decrypt encounters GOST_key_transport structure with NULL
299 public key field, it tries to use peerkey field from the context to
300 compute shared key. In this case peerkey field should really contain
301 peer public key.
302
303 Encrypt operation supports EVP_PKEY_CTRL_SET_IV operation as well.
304 It can be used when some specific restriction on UKM are imposed by
305 higher level protocol. For instance, description of GOST ciphersuites
306 requires UKM to be derived from shared secret. 
307
308 If UKM is not set by this control command, encrypt operation would
309 generate random UKM.
310
311
312 This sources include implementation of GOST 28147-89 and GOST R 34.11-94
313 which are completely indepentent from OpenSSL and can be used separately
314 (files gost89.c, gost89.h, gosthash.c, gosthash.h) Utility gostsum (file
315 gostsum.c) is provided as example of such separate usage. This is
316 program, simular to md5sum and sha1sum utilities, but calculates GOST R
317 34.11-94 hash.
318
319 Makefile doesn't include rule for compiling gostsum.
320 Use command
321
322 $(CC) -o gostsum gostsum.c gost89.c gosthash.c
323 where $(CC) is name of your C compiler.
324
325 Implementations of GOST R 34.10-xx, including VKO algorithms heavily
326 depends on OpenSSL BIGNUM and Elliptic Curve libraries.
327
328