You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by sc...@apache.org on 2011/06/28 16:29:08 UTC
svn commit: r1140638 - in /santuario/xml-security-cpp/trunk: configure.ac
xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.cpp xsec/framework/XSECW32Config.hpp
Author: scantor
Date: Tue Jun 28 14:29:08 2011
New Revision: 1140638
URL: http://svn.apache.org/viewvc?rev=1140638&view=rev
Log:
Copy in MGF routine for older OpenSSL versions.
Modified:
santuario/xml-security-cpp/trunk/configure.ac
santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.cpp
santuario/xml-security-cpp/trunk/xsec/framework/XSECW32Config.hpp
Modified: santuario/xml-security-cpp/trunk/configure.ac
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/configure.ac?rev=1140638&r1=1140637&r2=1140638&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/configure.ac (original)
+++ santuario/xml-security-cpp/trunk/configure.ac Tue Jun 28 14:29:08 2011
@@ -1,21 +1,19 @@
-# Copyright 2002-2011 The Apache Software Foundation.
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# All these setting come from the configure script
-# We use configure to do most of the hard work as it is more
-# designed to handle different system complexity than make
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
# Process this file with autoreconf
AC_PREREQ(2.50)
@@ -430,6 +428,10 @@ if test x"$use_openssl" != "xno" ; then
]])],[AC_MSG_RESULT([yes])
AC_DEFINE([XSEC_OPENSSL_HAVE_AES],[1],[Define to 1 if OpenSSL has full AES support.])],
[AC_MSG_RESULT([no])])
+
+ AC_CHECK_DECL(PKCS1_MGF1,
+ [AC_DEFINE([XSEC_OPENSSL_HAVE_MGF1],[1],[Define to 1 if OpenSSL has PKCS1_MGF1 function.])],
+ ,[#include <openssl/rsa.h>])
AC_CHECK_DECL(EVP_PKEY_set1_EC_KEY,
[AC_DEFINE([XSEC_OPENSSL_HAVE_EC],[1],[Define to 1 if OpenSSL has EC support.])],
Modified: santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.cpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.cpp?rev=1140638&r1=1140637&r2=1140638&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.cpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.cpp Tue Jun 28 14:29:08 2011
@@ -52,6 +52,53 @@ namespace {
// This code is modified from OpenSSL to implement SHA-2 hashing with OAEP.
// The MGF code is limited to SHA-1 in accordance with the XML Encryption spec.
+ // 0.9.8+ has a public MGF routine to call, this is a copy of it for older versions.
+
+#ifndef XSEC_OPENSSL_HAVE_MGF1
+ int PKCS1_MGF1(unsigned char *mask, long len,
+ const unsigned char *seed, long seedlen, const EVP_MD *dgst)
+ {
+ long i, outlen = 0;
+ unsigned char cnt[4];
+ EVP_MD_CTX c;
+ unsigned char md[EVP_MAX_MD_SIZE];
+ int mdlen;
+ int rv = -1;
+
+ EVP_MD_CTX_init(&c);
+ mdlen = EVP_MD_size(dgst);
+ if (mdlen < 0)
+ goto err;
+ for (i = 0; outlen < len; i++)
+ {
+ cnt[0] = (unsigned char)((i >> 24) & 255);
+ cnt[1] = (unsigned char)((i >> 16) & 255);
+ cnt[2] = (unsigned char)((i >> 8)) & 255;
+ cnt[3] = (unsigned char)(i & 255);
+ if (!EVP_DigestInit_ex(&c,dgst, NULL)
+ || !EVP_DigestUpdate(&c, seed, seedlen)
+ || !EVP_DigestUpdate(&c, cnt, 4))
+ goto err;
+ if (outlen + mdlen <= len)
+ {
+ if (!EVP_DigestFinal_ex(&c, mask + outlen, NULL))
+ goto err;
+ outlen += mdlen;
+ }
+ else
+ {
+ if (!EVP_DigestFinal_ex(&c, md, NULL))
+ goto err;
+ memcpy(mask + outlen, md, len - outlen);
+ outlen = len;
+ }
+ }
+ rv = 0;
+ err:
+ EVP_MD_CTX_cleanup(&c);
+ return rv;
+ }
+
static int MGF1(unsigned char *mask, long len, const unsigned char *seed, long seedlen)
{
return PKCS1_MGF1(mask, len, seed, seedlen, EVP_sha1());
@@ -83,7 +130,8 @@ namespace {
seed = to + 1;
db = to + digestlen + 1;
- EVP_Digest((void *)param, plen, db, NULL, digest, NULL);
+ if (!EVP_Digest((void *)param, plen, db, NULL, digest, NULL))
+ return 0;
memset(db + digestlen, 0,
emlen - flen - 2 * digestlen - 1);
db[emlen - flen - digestlen - 1] = 0x01;
@@ -168,7 +216,8 @@ namespace {
for (i = 0; i < dblen; i++)
db[i] ^= maskeddb[i];
- EVP_Digest((void *)param, plen, phash, NULL, digest, NULL);
+ if (!EVP_Digest((void *)param, plen, phash, NULL, digest, NULL))
+ return -1;
if (memcmp(db, phash, digestlen) != 0 || bad)
goto decoding_err;
Modified: santuario/xml-security-cpp/trunk/xsec/framework/XSECW32Config.hpp
URL: http://svn.apache.org/viewvc/santuario/xml-security-cpp/trunk/xsec/framework/XSECW32Config.hpp?rev=1140638&r1=1140637&r2=1140638&view=diff
==============================================================================
--- santuario/xml-security-cpp/trunk/xsec/framework/XSECW32Config.hpp (original)
+++ santuario/xml-security-cpp/trunk/xsec/framework/XSECW32Config.hpp Tue Jun 28 14:29:08 2011
@@ -193,6 +193,7 @@
# if (OPENSSL_VERSION_NUMBER >= 0x00908000)
# define XSEC_OPENSSL_D2IX509_CONST_BUFFER
# define XSEC_OPENSSL_HAVE_SHA2
+# define XSEC_OPENSSL_HAVE_MGF1
# endif
#endif