1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
|
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Cavium Networks
*/
#ifndef _RTE_CRYPTO_ASYM_H_
#define _RTE_CRYPTO_ASYM_H_
/**
* @file rte_crypto_asym.h
*
* RTE Definitions for Asymmetric Cryptography
*
* Defines asymmetric algorithms and modes, as well as supported
* asymmetric crypto operations.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include <stdint.h>
#include <rte_memory.h>
#include <rte_mempool.h>
#include <rte_common.h>
#include "rte_crypto_sym.h"
/**
* Buffer to hold crypto params required for asym operations.
*
* These buffers can be used for both input to PMD and output from PMD. When
* used for output from PMD, application has to ensure the buffer is large
* enough to hold the target data.
*/
typedef struct rte_crypto_param_t {
uint8_t *data;
/**< pointer to buffer holding data */
rte_iova_t iova;
/**< IO address of data buffer */
size_t length;
/**< length of data in bytes */
} rte_crypto_param;
/** asym xform type name strings */
extern const char *
rte_crypto_asym_xform_strings[];
/** asym operations type name strings */
extern const char *
rte_crypto_asym_op_strings[];
/**
* Asymmetric crypto transformation types.
* Each xform type maps to one asymmetric algorithm
* performing specific operation
*
*/
enum rte_crypto_asym_xform_type {
RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED = 0,
/**< Invalid xform. */
RTE_CRYPTO_ASYM_XFORM_NONE,
/**< Xform type None.
* May be supported by PMD to support
* passthrough op for debugging purpose.
* if xform_type none , op_type is disregarded.
*/
RTE_CRYPTO_ASYM_XFORM_RSA,
/**< RSA. Performs Encrypt, Decrypt, Sign and Verify.
* Refer to rte_crypto_asym_op_type
*/
RTE_CRYPTO_ASYM_XFORM_DH,
/**< Diffie-Hellman.
* Performs Key Generate and Shared Secret Compute.
* Refer to rte_crypto_asym_op_type
*/
RTE_CRYPTO_ASYM_XFORM_DSA,
/**< Digital Signature Algorithm
* Performs Signature Generation and Verification.
* Refer to rte_crypto_asym_op_type
*/
RTE_CRYPTO_ASYM_XFORM_MODINV,
/**< Modular Multiplicative Inverse
* Perform Modular Multiplicative Inverse b^(-1) mod n
*/
RTE_CRYPTO_ASYM_XFORM_MODEX,
/**< Modular Exponentiation
* Perform Modular Exponentiation b^e mod n
*/
RTE_CRYPTO_ASYM_XFORM_ECDSA,
/**< Elliptic Curve Digital Signature Algorithm
* Perform Signature Generation and Verification.
*/
RTE_CRYPTO_ASYM_XFORM_ECPM,
/**< Elliptic Curve Point Multiplication */
RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
/**< End of list */
};
/**
* Asymmetric crypto operation type variants
*/
enum rte_crypto_asym_op_type {
RTE_CRYPTO_ASYM_OP_ENCRYPT,
/**< Asymmetric Encrypt operation */
RTE_CRYPTO_ASYM_OP_DECRYPT,
/**< Asymmetric Decrypt operation */
RTE_CRYPTO_ASYM_OP_SIGN,
/**< Signature Generation operation */
RTE_CRYPTO_ASYM_OP_VERIFY,
/**< Signature Verification operation */
RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE,
/**< DH Private Key generation operation */
RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE,
/**< DH Public Key generation operation */
RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE,
/**< DH Shared Secret compute operation */
RTE_CRYPTO_ASYM_OP_LIST_END
};
/**
* Padding types for RSA signature.
*/
enum rte_crypto_rsa_padding_type {
RTE_CRYPTO_RSA_PADDING_NONE = 0,
/**< RSA no padding scheme */
RTE_CRYPTO_RSA_PADDING_PKCS1_5,
/**< RSA PKCS#1 PKCS1-v1_5 padding scheme. For signatures block type 01,
* for encryption block type 02 are used.
*/
RTE_CRYPTO_RSA_PADDING_OAEP,
/**< RSA PKCS#1 OAEP padding scheme */
RTE_CRYPTO_RSA_PADDING_PSS,
/**< RSA PKCS#1 PSS padding scheme */
RTE_CRYPTO_RSA_PADDING_TYPE_LIST_END
};
/**
* RSA private key type enumeration
*
* enumerates private key format required to perform RSA crypto
* transform.
*
*/
enum rte_crypto_rsa_priv_key_type {
RTE_RSA_KEY_TYPE_EXP,
/**< RSA private key is an exponent */
RTE_RSA_KET_TYPE_QT,
/**< RSA private key is in quintuple format
* See rte_crypto_rsa_priv_key_qt
*/
};
/**
* Structure describing RSA private key in quintuple format.
* See PKCS V1.5 RSA Cryptography Standard.
*/
struct rte_crypto_rsa_priv_key_qt {
rte_crypto_param p;
/**< p - Private key component P
* Private key component of RSA parameter required for CRT method
* of private key operations in Octet-string network byte order
* format.
*/
rte_crypto_param q;
/**< q - Private key component Q
* Private key component of RSA parameter required for CRT method
* of private key operations in Octet-string network byte order
* format.
*/
rte_crypto_param dP;
/**< dP - Private CRT component
* Private CRT component of RSA parameter required for CRT method
* RSA private key operations in Octet-string network byte order
* format.
* dP = d mod ( p - 1 )
*/
rte_crypto_param dQ;
/**< dQ - Private CRT component
* Private CRT component of RSA parameter required for CRT method
* RSA private key operations in Octet-string network byte order
* format.
* dQ = d mod ( q - 1 )
*/
rte_crypto_param qInv;
/**< qInv - Private CRT component
* Private CRT component of RSA parameter required for CRT method
* RSA private key operations in Octet-string network byte order
* format.
* qInv = inv q mod p
*/
};
/**
* Asymmetric RSA transform data
*
* Structure describing RSA xform params
*
*/
struct rte_crypto_rsa_xform {
rte_crypto_param n;
/**< n - Modulus
* Modulus data of RSA operation in Octet-string network
* byte order format.
*/
rte_crypto_param e;
/**< e - Public key exponent
* Public key exponent used for RSA public key operations in Octet-
* string network byte order format.
*/
enum rte_crypto_rsa_priv_key_type key_type;
__extension__
union {
rte_crypto_param d;
/**< d - Private key exponent
* Private key exponent used for RSA
* private key operations in
* Octet-string network byte order format.
*/
struct rte_crypto_rsa_priv_key_qt qt;
/**< qt - Private key in quintuple format */
};
};
/**
* Asymmetric Modular exponentiation transform data
*
* Structure describing modular exponentiation xform param
*
*/
struct rte_crypto_modex_xform {
rte_crypto_param modulus;
/**< modulus
* Pointer to the modulus data for modexp transform operation
* in octet-string network byte order format
*
* In case this number is equal to zero the driver shall set
* the crypto op status field to RTE_CRYPTO_OP_STATUS_ERROR
*/
rte_crypto_param exponent;
/**< exponent
* Exponent of the modexp transform operation in
* octet-string network byte order format
*/
};
/**
* Asymmetric modular multiplicative inverse transform operation
*
* Structure describing modular multiplicative inverse transform
*
*/
struct rte_crypto_modinv_xform {
rte_crypto_param modulus;
/**<
* Pointer to the modulus data for modular multiplicative inverse
* operation in octet-string network byte order format
*
* In case this number is equal to zero the driver shall set
* the crypto op status field to RTE_CRYPTO_OP_STATUS_ERROR
*
* This number shall be relatively prime to base
* in corresponding Modular Multiplicative Inverse
* rte_crypto_mod_op_param
*/
};
/**
* Asymmetric DH transform data
*
* Structure describing deffie-hellman xform params
*
*/
struct rte_crypto_dh_xform {
enum rte_crypto_asym_op_type type;
/**< Setup xform for key generate or shared secret compute */
rte_crypto_param p;
/**< p : Prime modulus data
* DH prime modulus data in octet-string network byte order format.
*
*/
rte_crypto_param g;
/**< g : Generator
* DH group generator data in octet-string network byte order
* format.
*
*/
};
/**
* Asymmetric Digital Signature transform operation
*
* Structure describing DSA xform params
*
*/
struct rte_crypto_dsa_xform {
rte_crypto_param p;
/**< p - Prime modulus
* Prime modulus data for DSA operation in Octet-string network byte
* order format.
*/
rte_crypto_param q;
/**< q : Order of the subgroup.
* Order of the subgroup data in Octet-string network byte order
* format.
* (p-1) % q = 0
*/
rte_crypto_param g;
/**< g: Generator of the subgroup
* Generator data in Octet-string network byte order format.
*/
rte_crypto_param x;
/**< x: Private key of the signer in octet-string network
* byte order format.
* Used when app has pre-defined private key.
* Valid only when xform chain is DSA ONLY.
* if xform chain is DH private key generate + DSA, then DSA sign
* compute will use internally generated key.
*/
};
/**
* TLS named curves
* https://tools.ietf.org/html/rfc8422
*/
enum rte_crypto_ec_group {
RTE_CRYPTO_EC_GROUP_UNKNOWN = 0,
RTE_CRYPTO_EC_GROUP_SECP192R1 = 19,
RTE_CRYPTO_EC_GROUP_SECP224R1 = 21,
RTE_CRYPTO_EC_GROUP_SECP256R1 = 23,
RTE_CRYPTO_EC_GROUP_SECP384R1 = 24,
RTE_CRYPTO_EC_GROUP_SECP521R1 = 25,
};
/**
* Structure for elliptic curve point
*/
struct rte_crypto_ec_point {
rte_crypto_param x;
/**< X coordinate */
rte_crypto_param y;
/**< Y coordinate */
};
/**
* Asymmetric elliptic curve transform data
*
* Structure describing all EC based xform params
*
*/
struct rte_crypto_ec_xform {
enum rte_crypto_ec_group curve_id;
/**< Pre-defined ec groups */
};
/**
* Operations params for modular operations:
* exponentiation and multiplicative inverse
*
*/
struct rte_crypto_mod_op_param {
rte_crypto_param base;
/**<
* Pointer to base of modular exponentiation/multiplicative
* inverse data in octet-string network byte order format
*
* In case Multiplicative Inverse is used this number shall
* be relatively prime to modulus in corresponding Modular
* Multiplicative Inverse rte_crypto_modinv_xform
*/
rte_crypto_param result;
/**<
* Pointer to the result of modular exponentiation/multiplicative inverse
* data in octet-string network byte order format.
*
* This field shall be big enough to hold the result of Modular
* Exponentiation or Modular Multiplicative Inverse
* (bigger or equal to length of modulus)
*/
};
/**
* Asymmetric crypto transform data
*
* Structure describing asym xforms.
*/
struct rte_crypto_asym_xform {
struct rte_crypto_asym_xform *next;
/**< Pointer to next xform to set up xform chain.*/
enum rte_crypto_asym_xform_type xform_type;
/**< Asymmetric crypto transform */
__extension__
union {
struct rte_crypto_rsa_xform rsa;
/**< RSA xform parameters */
struct rte_crypto_modex_xform modex;
/**< Modular Exponentiation xform parameters */
struct rte_crypto_modinv_xform modinv;
/**< Modular Multiplicative Inverse xform parameters */
struct rte_crypto_dh_xform dh;
/**< DH xform parameters */
struct rte_crypto_dsa_xform dsa;
/**< DSA xform parameters */
struct rte_crypto_ec_xform ec;
/**< EC xform parameters, used by elliptic curve based
* operations.
*/
};
};
struct rte_cryptodev_asym_session;
/**
* RSA operation params
*
*/
struct rte_crypto_rsa_op_param {
enum rte_crypto_asym_op_type op_type;
/**< Type of RSA operation for transform */
rte_crypto_param message;
/**<
* Pointer to input data
* - to be encrypted for RSA public encrypt.
* - to be signed for RSA sign generation.
* - to be authenticated for RSA sign verification.
*
* Pointer to output data
* - for RSA private decrypt.
* In this case the underlying array should have been
* allocated with enough memory to hold plaintext output
* (i.e. must be at least RSA key size). The message.length
* field should be 0 and will be overwritten by the PMD
* with the decrypted length.
*
* All data is in Octet-string network byte order format.
*/
rte_crypto_param cipher;
/**<
* Pointer to input data
* - to be decrypted for RSA private decrypt.
*
* Pointer to output data
* - for RSA public encrypt.
* In this case the underlying array should have been allocated
* with enough memory to hold ciphertext output (i.e. must be
* at least RSA key size). The cipher.length field should
* be 0 and will be overwritten by the PMD with the encrypted length.
*
* All data is in Octet-string network byte order format.
*/
rte_crypto_param sign;
/**<
* Pointer to input data
* - to be verified for RSA public decrypt.
*
* Pointer to output data
* - for RSA private encrypt.
* In this case the underlying array should have been allocated
* with enough memory to hold signature output (i.e. must be
* at least RSA key size). The sign.length field should
* be 0 and will be overwritten by the PMD with the signature length.
*
* All data is in Octet-string network byte order format.
*/
enum rte_crypto_rsa_padding_type pad;
/**< RSA padding scheme to be used for transform */
enum rte_crypto_auth_algorithm md;
/**< Hash algorithm to be used for data hash if padding
* scheme is either OAEP or PSS. Valid hash algorithms
* are:
* MD5, SHA1, SHA224, SHA256, SHA384, SHA512
*/
enum rte_crypto_auth_algorithm mgf1md;
/**<
* Hash algorithm to be used for mask generation if
* padding scheme is either OAEP or PSS. If padding
* scheme is unspecified data hash algorithm is used
* for mask generation. Valid hash algorithms are:
* MD5, SHA1, SHA224, SHA256, SHA384, SHA512
*/
};
/**
* Diffie-Hellman Operations params.
* @note:
*/
struct rte_crypto_dh_op_param {
rte_crypto_param pub_key;
/**<
* Output generated public key when xform type is
* DH PUB_KEY_GENERATION.
* Input peer public key when xform type is DH
* SHARED_SECRET_COMPUTATION
* pub_key is in octet-string network byte order format.
*
*/
rte_crypto_param priv_key;
/**<
* Output generated private key if xform type is
* DH PRIVATE_KEY_GENERATION
* Input when xform type is DH SHARED_SECRET_COMPUTATION.
* priv_key is in octet-string network byte order format.
*
*/
rte_crypto_param shared_secret;
/**<
* Output with calculated shared secret
* when dh xform set up with op type = SHARED_SECRET_COMPUTATION.
* shared_secret is an octet-string network byte order format.
*
*/
};
/**
* DSA Operations params
*
*/
struct rte_crypto_dsa_op_param {
enum rte_crypto_asym_op_type op_type;
/**< Signature Generation or Verification */
rte_crypto_param message;
/**< input message to be signed or verified */
rte_crypto_param r;
/**< dsa sign component 'r' value
*
* output if op_type = sign generate,
* input if op_type = sign verify
*/
rte_crypto_param s;
/**< dsa sign component 's' value
*
* output if op_type = sign generate,
* input if op_type = sign verify
*/
rte_crypto_param y;
/**< y : Public key of the signer.
* Public key data of the signer in Octet-string network byte order
* format.
* y = g^x mod p
*/
};
/**
* ECDSA operation params
*/
struct rte_crypto_ecdsa_op_param {
enum rte_crypto_asym_op_type op_type;
/**< Signature generation or verification */
rte_crypto_param pkey;
/**< Private key of the signer for signature generation */
struct rte_crypto_ec_point q;
/**< Public key of the signer for verification */
rte_crypto_param message;
/**< Input message digest to be signed or verified */
rte_crypto_param k;
/**< The ECDSA per-message secret number, which is an integer
* in the interval (1, n-1)
*/
rte_crypto_param r;
/**< r component of elliptic curve signature
* output : for signature generation
* input : for signature verification
*/
rte_crypto_param s;
/**< s component of elliptic curve signature
* output : for signature generation
* input : for signature verification
*/
};
/**
* Structure for EC point multiplication operation param
*/
struct rte_crypto_ecpm_op_param {
struct rte_crypto_ec_point p;
/**< x and y coordinates of input point */
struct rte_crypto_ec_point r;
/**< x and y coordinates of resultant point */
rte_crypto_param scalar;
/**< Scalar to multiply the input point */
};
/**
* Asymmetric Cryptographic Operation.
*
* Structure describing asymmetric crypto operation params.
*
*/
struct rte_crypto_asym_op {
RTE_STD_C11
union {
struct rte_cryptodev_asym_session *session;
/**< Handle for the initialised session context */
struct rte_crypto_asym_xform *xform;
/**< Session-less API crypto operation parameters */
};
__extension__
union {
struct rte_crypto_rsa_op_param rsa;
struct rte_crypto_mod_op_param modex;
struct rte_crypto_mod_op_param modinv;
struct rte_crypto_dh_op_param dh;
struct rte_crypto_dsa_op_param dsa;
struct rte_crypto_ecdsa_op_param ecdsa;
struct rte_crypto_ecpm_op_param ecpm;
};
};
#ifdef __cplusplus
}
#endif
#endif /* _RTE_CRYPTO_ASYM_H_ */
|