Fix a endianness bug while reading the public exponent attribute from
public template (for ica).

Signed-off-by: Ramon de Carvalho Valle <[email protected]>
---
 usr/lib/pkcs11/ica_s390_stdll/ica_specific.c |    9 +++++++++
 usr/lib/pkcs11/ica_stdll/ica_specific.c      |    9 +++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/usr/lib/pkcs11/ica_s390_stdll/ica_specific.c 
b/usr/lib/pkcs11/ica_s390_stdll/ica_specific.c
index 03c2545..dc73488 100755
--- a/usr/lib/pkcs11/ica_s390_stdll/ica_specific.c
+++ b/usr/lib/pkcs11/ica_s390_stdll/ica_specific.c
@@ -1786,7 +1786,16 @@ os_specific_rsa_keygen(TEMPLATE *publ_tmpl,  TEMPLATE 
*priv_tmpl)
     * all fields must be right-aligned, so make
     * sure we only use the rightmost part */
    ptr = publKey->exponent + publKey->key_length - publ_exp->ulValueLen;
+
+#ifndef __BYTE_ORDER
+#error "Architecture endianness is not defined."
+#endif
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
    memcpy(ptr, publ_exp->pValue, publ_exp->ulValueLen);
+#else
+   memcpy(ptr + (sizeof(unsigned long) - publ_exp->ulValueLen), 
publ_exp->pValue, publ_exp->ulValueLen);
+#endif
 
    /* Build privKey:
     * buffers pointed by p, q, dp, dq and qInverse in struct
diff --git a/usr/lib/pkcs11/ica_stdll/ica_specific.c 
b/usr/lib/pkcs11/ica_stdll/ica_specific.c
index 2a6fdf9..0c26a57 100755
--- a/usr/lib/pkcs11/ica_stdll/ica_specific.c
+++ b/usr/lib/pkcs11/ica_stdll/ica_specific.c
@@ -824,7 +824,16 @@ os_specific_rsa_keygen(TEMPLATE *publ_tmpl,  TEMPLATE 
*priv_tmpl)
 
 
    ptr = publKey->keyRecord + keysize - publ_exp->ulValueLen;
+
+#ifndef __BYTE_ORDER
+#error "Architecture endianness is not defined."
+#endif
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
    memcpy(ptr,publ_exp->pValue, publ_exp->ulValueLen);    
+#else
+   memcpy(ptr + (sizeof(unsigned long) - publ_exp->ulValueLen), 
publ_exp->pValue, publ_exp->ulValueLen);
+#endif
 
    publKeySize = sizeof(ICA_KEY_RSA_MODEXPO);
    privKeySize = sizeof(ICA_KEY_RSA_CRT);
-- 
1.6.3.3


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Opencryptoki-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opencryptoki-tech

Reply via email to