summaryrefslogtreecommitdiffstats
path: root/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch')
-rw-r--r--recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch153
1 files changed, 153 insertions, 0 deletions
diff --git a/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch
new file mode 100644
index 0000000..244d230
--- /dev/null
+++ b/recipes-connectivity/openssl/openssl-qoriq/qoriq/0011-Add-RSA-keygen-operation-and-support-gendsa-command-.patch
@@ -0,0 +1,153 @@
1From e4fc051f8ae1c093b25ca346c2ec351ff3b700d1 Mon Sep 17 00:00:00 2001
2From: Hou Zhiqiang <B48286@freescale.com>
3Date: Wed, 2 Apr 2014 16:10:43 +0800
4Subject: [PATCH 11/26] Add RSA keygen operation and support gendsa command
5 with hardware engine
6
7Upstream-status: Pending
8
9Signed-off-by: Hou Zhiqiang <B48286@freescale.com>
10Tested-by: Cristian Stoica <cristian.stoica@freescale.com>
11---
12 crypto/engine/eng_cryptodev.c | 118 ++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 118 insertions(+)
14
15diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
16index 9f2416e..b2919a8 100644
17--- a/crypto/engine/eng_cryptodev.c
18+++ b/crypto/engine/eng_cryptodev.c
19@@ -1906,6 +1906,121 @@ err:
20 return dsaret;
21 }
22
23+/* Cryptodev RSA Key Gen routine */
24+static int cryptodev_rsa_keygen(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
25+{
26+ struct crypt_kop kop;
27+ int ret, fd;
28+ int p_len, q_len;
29+ int i;
30+
31+ if ((fd = get_asym_dev_crypto()) < 0)
32+ return fd;
33+
34+ if(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err;
35+ if(!rsa->d && ((rsa->d=BN_new()) == NULL)) goto err;
36+ if(!rsa->e && ((rsa->e=BN_new()) == NULL)) goto err;
37+ if(!rsa->p && ((rsa->p=BN_new()) == NULL)) goto err;
38+ if(!rsa->q && ((rsa->q=BN_new()) == NULL)) goto err;
39+ if(!rsa->dmp1 && ((rsa->dmp1=BN_new()) == NULL)) goto err;
40+ if(!rsa->dmq1 && ((rsa->dmq1=BN_new()) == NULL)) goto err;
41+ if(!rsa->iqmp && ((rsa->iqmp=BN_new()) == NULL)) goto err;
42+
43+ BN_copy(rsa->e, e);
44+
45+ p_len = (bits+1) / (2 * 8);
46+ q_len = (bits - p_len * 8) / 8;
47+ memset(&kop, 0, sizeof kop);
48+ kop.crk_op = CRK_RSA_GENERATE_KEY;
49+
50+ /* p length */
51+ kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char));
52+ if (!kop.crk_param[kop.crk_iparams].crp_p)
53+ goto err;
54+ kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8;
55+ memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1);
56+ kop.crk_iparams++;
57+ kop.crk_oparams++;
58+ /* q length */
59+ kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char));
60+ if (!kop.crk_param[kop.crk_iparams].crp_p)
61+ goto err;
62+ kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8;
63+ memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1);
64+ kop.crk_iparams++;
65+ kop.crk_oparams++;
66+ /* n length */
67+ kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + q_len + 1, sizeof(char));
68+ if (!kop.crk_param[kop.crk_iparams].crp_p)
69+ goto err;
70+ kop.crk_param[kop.crk_iparams].crp_nbits = bits;
71+ memset(kop.crk_param[kop.crk_iparams].crp_p, 0x00, p_len + q_len + 1);
72+ kop.crk_iparams++;
73+ kop.crk_oparams++;
74+ /* d length */
75+ kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + q_len + 1, sizeof(char));
76+ if (!kop.crk_param[kop.crk_iparams].crp_p)
77+ goto err;
78+ kop.crk_param[kop.crk_iparams].crp_nbits = bits;
79+ memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + q_len + 1);
80+ kop.crk_iparams++;
81+ kop.crk_oparams++;
82+ /* dp1 length */
83+ kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char));
84+ if (!kop.crk_param[kop.crk_iparams].crp_p)
85+ goto err;
86+ kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8;
87+ memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1);
88+ kop.crk_iparams++;
89+ kop.crk_oparams++;
90+ /* dq1 length */
91+ kop.crk_param[kop.crk_iparams].crp_p = calloc(q_len + 1, sizeof(char));
92+ if (!kop.crk_param[kop.crk_iparams].crp_p)
93+ goto err;
94+ kop.crk_param[kop.crk_iparams].crp_nbits = q_len * 8;
95+ memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, q_len + 1);
96+ kop.crk_iparams++;
97+ kop.crk_oparams++;
98+ /* i length */
99+ kop.crk_param[kop.crk_iparams].crp_p = calloc(p_len + 1, sizeof(char));
100+ if (!kop.crk_param[kop.crk_iparams].crp_p)
101+ goto err;
102+ kop.crk_param[kop.crk_iparams].crp_nbits = p_len * 8;
103+ memset(kop.crk_param[kop.crk_iparams].crp_p, 0xff, p_len + 1);
104+ kop.crk_iparams++;
105+ kop.crk_oparams++;
106+
107+ if (ioctl(fd, CIOCKEY, &kop) == 0) {
108+ BN_bin2bn(kop.crk_param[0].crp_p,
109+ p_len, rsa->p);
110+ BN_bin2bn(kop.crk_param[1].crp_p,
111+ q_len, rsa->q);
112+ BN_bin2bn(kop.crk_param[2].crp_p,
113+ bits / 8, rsa->n);
114+ BN_bin2bn(kop.crk_param[3].crp_p,
115+ bits / 8, rsa->d);
116+ BN_bin2bn(kop.crk_param[4].crp_p,
117+ p_len, rsa->dmp1);
118+ BN_bin2bn(kop.crk_param[5].crp_p,
119+ q_len, rsa->dmq1);
120+ BN_bin2bn(kop.crk_param[6].crp_p,
121+ p_len, rsa->iqmp);
122+ return 1;
123+ }
124+sw_try:
125+ {
126+ const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
127+ ret = (meth->rsa_keygen)(rsa, bits, e, cb);
128+ }
129+ return ret;
130+
131+err:
132+ for (i = 0; i < CRK_MAXPARAM; i++)
133+ free(kop.crk_param[i].crp_p);
134+ return 0;
135+
136+}
137+
138 /* Cryptodev DSA Key Gen routine */
139 static int cryptodev_dsa_keygen(DSA *dsa)
140 {
141@@ -3896,6 +4011,9 @@ ENGINE_load_cryptodev(void)
142 cryptodev_rsa.rsa_mod_exp_async =
143 cryptodev_rsa_nocrt_mod_exp_async;
144 }
145+ if (cryptodev_asymfeat & CRF_RSA_GENERATE_KEY)
146+ cryptodev_rsa.rsa_keygen =
147+ cryptodev_rsa_keygen;
148 }
149 }
150
151--
1522.3.5
153