[xmlsec] cleanup Endian handling on mscrypto
- From: Aleksey Sanin <aleksey src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [xmlsec] cleanup Endian handling on mscrypto
- Date: Fri, 30 Apr 2010 07:01:30 +0000 (UTC)
commit a207230541dca3afe94f47a7d3b191d63129720f
Author: Aleksey Sanin <aleksey aleksey com>
Date: Thu Apr 29 22:40:35 2010 -0700
cleanup Endian handling on mscrypto
src/mscrypto/README | 5 +--
src/mscrypto/crypto.c | 41 ++++++++++++++++++++++++
src/mscrypto/kt_rsa.c | 19 ++---------
src/mscrypto/private.h | 75 +++++++++++++++++++++++++-------------------
src/mscrypto/signatures.c | 16 ---------
5 files changed, 89 insertions(+), 67 deletions(-)
---
diff --git a/src/mscrypto/README b/src/mscrypto/README
index 3086024..01677b0 100644
--- a/src/mscrypto/README
+++ b/src/mscrypto/README
@@ -41,10 +41,7 @@ KNOWN ISSUES.
- DES KW (http://bugzilla.gnome.org/show_bug.cgi?id=123673): no native
support, might be possible to implement on top of AES cipher itself
-3) Actual AES Crypto provider name is different from the "official" one
-(http://bugzilla.gnome.org/show_bug.cgi?id=123674).
-
-4) The only supported file formats are PKCS#12 and DER certificates
+3) The only supported file formats are PKCS#12 and DER certificates
(http://bugzilla.gnome.org/show_bug.cgi?id=123675).
diff --git a/src/mscrypto/crypto.c b/src/mscrypto/crypto.c
index ef20392..b00e936 100644
--- a/src/mscrypto/crypto.c
+++ b/src/mscrypto/crypto.c
@@ -734,6 +734,11 @@ xmlSecMSCryptoConvertUtf8ToTstr(const xmlChar* str) {
#endif /* UNICODE */
}
+/********************************************************************
+ *
+ * Crypto Providers
+ *
+ ********************************************************************/
/**
* xmlSecMSCryptoFindProvider:
* @providers: the pointer to list of providers, last provider should have NULL for name.
@@ -821,4 +826,40 @@ xmlSecMSCryptoFindProvider(const xmlSecMSCryptoProviderInfo * providers,
}
+/********************************************************************
+ *
+ * Utils
+ *
+ ********************************************************************/
+int
+ConvertEndian(const xmlSecByte * src, xmlSecByte * dst, xmlSecSize size) {
+ xmlSecByte * p;
+
+ xmlSecAssert2(src != NULL, -1);
+ xmlSecAssert2(dst != NULL, -1);
+ xmlSecAssert2(size > 0, -1);
+
+ for(p = dst + size - 1; p >= dst; ++src, --p) {
+ (*p) = (*src);
+ }
+
+ return (0);
+}
+
+int
+ConvertEndianInPlace(xmlSecByte * buf, xmlSecSize size) {
+ xmlSecByte * p;
+ xmlSecByte ch;
+
+ xmlSecAssert2(buf != NULL, -1);
+ xmlSecAssert2(size > 0, -1);
+
+ for(p = buf + size - 1; p >= buf; ++buf, --p) {
+ ch = (*p);
+ (*p) = (*buf);
+ (*buf) = ch;
+ }
+ return (0);
+}
+
diff --git a/src/mscrypto/kt_rsa.c b/src/mscrypto/kt_rsa.c
index 0faa607..b6364a7 100644
--- a/src/mscrypto/kt_rsa.c
+++ b/src/mscrypto/kt_rsa.c
@@ -244,8 +244,8 @@ xmlSecMSCryptoRsaPkcs1Process(xmlSecTransformPtr transform, xmlSecTransformCtxPt
DWORD dwInLen;
DWORD dwBufLen;
DWORD dwOutLen;
- BYTE * outBuf;
- BYTE * inBuf;
+ xmlSecByte * outBuf;
+ xmlSecByte * inBuf;
int i;
xmlSecAssert2(xmlSecTransformCheckId(transform, xmlSecMSCryptoTransformRsaPkcs1Id), -1);
@@ -297,8 +297,6 @@ xmlSecMSCryptoRsaPkcs1Process(xmlSecTransformPtr transform, xmlSecTransformCtxPt
}
if(transform->operation == xmlSecTransformOperationEncrypt) {
- BYTE ch;
-
if(inSize > outSize) {
xmlSecError(XMLSEC_ERRORS_HERE,
xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
@@ -344,11 +342,7 @@ xmlSecMSCryptoRsaPkcs1Process(xmlSecTransformPtr transform, xmlSecTransformCtxPt
/* The output of CryptEncrypt is in little-endian format, so we have to convert to
* big-endian first.
*/
- for(i = 0; i < outSize / 2; i++) {
- ch = outBuf[i];
- outBuf[i] = outBuf[outSize - (i + 1)];
- outBuf[outSize - (i + 1)] = ch;
- }
+ ConvertEndianInPlace(outBuf, outSize);
} else {
dwOutLen = inSize;
@@ -357,12 +351,7 @@ xmlSecMSCryptoRsaPkcs1Process(xmlSecTransformPtr transform, xmlSecTransformCtxPt
*/
inBuf = xmlSecBufferGetData(in);
outBuf = xmlSecBufferGetData(out);
-
- xmlSecAssert2(inBuf != 0, -1);
- xmlSecAssert2(outBuf != 0, -1);
- for (i = 0; i < inSize; i++) {
- outBuf[i] = inBuf[inSize - (i + 1)];
- }
+ ConvertEndian(inBuf, outBuf, inSize);
if (0 == (hKey = xmlSecMSCryptoKeyDataGetDecryptKey(ctx->data))) {
xmlSecError(XMLSEC_ERRORS_HERE,
diff --git a/src/mscrypto/private.h b/src/mscrypto/private.h
index adbed25..d56332d 100644
--- a/src/mscrypto/private.h
+++ b/src/mscrypto/private.h
@@ -22,6 +22,17 @@ extern "C" {
/********************************************************************
*
+ * Utils
+ *
+ ********************************************************************/
+int ConvertEndian (const xmlSecByte * src,
+ xmlSecByte * dst,
+ xmlSecSize size);
+int ConvertEndianInPlace (xmlSecByte * buf,
+ xmlSecSize size);
+
+/********************************************************************
+ *
* Crypto Providers
*
********************************************************************/
@@ -53,10 +64,10 @@ typedef struct _xmlSecMSCryptoProviderInfo {
DWORD providerType;
} xmlSecMSCryptoProviderInfo;
-XMLSEC_CRYPTO_EXPORT HCRYPTPROV xmlSecMSCryptoFindProvider (const xmlSecMSCryptoProviderInfo * providers,
- LPCTSTR pszContainer,
- DWORD dwFlags,
- BOOL bUseXmlSecContainer);
+HCRYPTPROV xmlSecMSCryptoFindProvider (const xmlSecMSCryptoProviderInfo * providers,
+ LPCTSTR pszContainer,
+ DWORD dwFlags,
+ BOOL bUseXmlSecContainer);
/******************************************************************************
@@ -69,16 +80,16 @@ XMLSEC_CRYPTO_EXPORT HCRYPTPROV xmlSecMSCryptoFindProvider (const x
* and "Base Provider Key BLOBs" article for priv key blob format.
*
******************************************************************************/
-XMLSEC_CRYPTO_EXPORT BOOL xmlSecMSCryptoCreatePrivateExponentOneKey (HCRYPTPROV hProv,
- HCRYPTKEY *hPrivateKey);
+BOOL xmlSecMSCryptoCreatePrivateExponentOneKey (HCRYPTPROV hProv,
+ HCRYPTKEY *hPrivateKey);
-XMLSEC_CRYPTO_EXPORT BOOL xmlSecMSCryptoImportPlainSessionBlob (HCRYPTPROV hProv,
- HCRYPTKEY hPrivateKey,
- ALG_ID dwAlgId,
- LPBYTE pbKeyMaterial,
- DWORD dwKeyMaterial,
- BOOL bCheckKeyLength,
- HCRYPTKEY *hSessionKey);
+BOOL xmlSecMSCryptoImportPlainSessionBlob (HCRYPTPROV hProv,
+ HCRYPTKEY hPrivateKey,
+ ALG_ID dwAlgId,
+ LPBYTE pbKeyMaterial,
+ DWORD dwKeyMaterial,
+ BOOL bCheckKeyLength,
+ HCRYPTKEY *hSessionKey);
/******************************************************************************
*
@@ -86,25 +97,25 @@ XMLSEC_CRYPTO_EXPORT BOOL xmlSecMSCryptoImportPlainSessionBlob (HC
*
******************************************************************************/
#ifndef XMLSEC_NO_X509
-XMLSEC_CRYPTO_EXPORT PCCERT_CONTEXT xmlSecMSCryptoX509FindCertBySubject (HCERTSTORE store,
- const LPTSTR wcSubject,
- DWORD dwCertEncodingType);
-
-XMLSEC_CRYPTO_EXPORT PCCERT_CONTEXT xmlSecMSCryptoX509StoreFindCert (xmlSecKeyDataStorePtr store,
- xmlChar *subjectName,
- xmlChar *issuerName,
- xmlChar *issuerSerial,
- xmlChar *ski,
- xmlSecKeyInfoCtx* keyInfoCtx);
-
-XMLSEC_CRYPTO_EXPORT xmlChar * xmlSecMSCryptoX509GetNameString (PCCERT_CONTEXT pCertContext,
- DWORD dwType,
- DWORD dwFlags,
- void *pvTypePara);
-
-XMLSEC_CRYPTO_EXPORT PCCERT_CONTEXT xmlSecMSCryptoX509StoreVerify (xmlSecKeyDataStorePtr store,
- HCERTSTORE certs,
- xmlSecKeyInfoCtx* keyInfoCtx);
+PCCERT_CONTEXT xmlSecMSCryptoX509FindCertBySubject (HCERTSTORE store,
+ const LPTSTR wcSubject,
+ DWORD dwCertEncodingType);
+
+PCCERT_CONTEXT xmlSecMSCryptoX509StoreFindCert (xmlSecKeyDataStorePtr store,
+ xmlChar *subjectName,
+ xmlChar *issuerName,
+ xmlChar *issuerSerial,
+ xmlChar *ski,
+ xmlSecKeyInfoCtx* keyInfoCtx);
+
+xmlChar * xmlSecMSCryptoX509GetNameString (PCCERT_CONTEXT pCertContext,
+ DWORD dwType,
+ DWORD dwFlags,
+ void *pvTypePara);
+
+PCCERT_CONTEXT xmlSecMSCryptoX509StoreVerify (xmlSecKeyDataStorePtr store,
+ HCERTSTORE certs,
+ xmlSecKeyInfoCtx* keyInfoCtx);
#endif /* XMLSEC_NO_X509 */
diff --git a/src/mscrypto/signatures.c b/src/mscrypto/signatures.c
index 55ed749..53c10d1 100644
--- a/src/mscrypto/signatures.c
+++ b/src/mscrypto/signatures.c
@@ -287,22 +287,6 @@ static int xmlSecMSCryptoSignatureSetKeyReq(xmlSecTransformPtr transform, xmlSe
return(0);
}
-static int ConvertEndian(const xmlSecByte * src, xmlSecByte * dst, int size) {
- BYTE * p;
-
- xmlSecAssert2(src != NULL, -1);
- xmlSecAssert2(dst != NULL, -1);
- xmlSecAssert2(size > 0, -1);
-
- p = dst + size - 1;
- while (p >= dst) {
- *(p--) = *(src++);
- }
-
- return (0);
-}
-
-
static int xmlSecMSCryptoSignatureVerify(xmlSecTransformPtr transform,
const xmlSecByte* data,
xmlSecSize dataSize,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]