]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
RC2 was made reentrant. The stddef.h is now included if found.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 13 Aug 2003 10:25:46 +0000 (10:25 +0000)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Wed, 13 Aug 2003 10:25:46 +0000 (10:25 +0000)
configure.in
lib/defines.h
lib/rc2.c

index 5ad3f1a9380560fb659e1acdb5cbfd8c285751f8..7f7bf916d9ea39dcb69daccdb5f8c025523b8374 100644 (file)
@@ -155,7 +155,7 @@ AC_MSG_RESULT([***
 
 AC_HEADER_STDC
 AC_HEADER_TIME
-AC_CHECK_HEADERS(unistd.h strings.h)
+AC_CHECK_HEADERS(unistd.h strings.h stddef.h)
 AC_CHECK_HEADERS(sys/stat.h sys/types.h sys/socket.h)
 AC_CHECK_HEADERS(errno.h sys/time.h time.h)
 AC_CHECK_FUNCS(memset memmove strnstr memcmp memcpy mmap,,)
index 4524ade3cad7ebf4144a4e29f61ce61cc0ff170d..171f7c1a3215b4f03bd591083cbb7b097200c298 100644 (file)
@@ -61,6 +61,10 @@ typedef long ptrdiff_t;
 char *strnstr(const char *haystack, const char *needle, size_t haystacklen);
 #endif
 
+#ifdef HAVE_STDDEF_H
+# include <stddef.h>
+#endif
+
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 #endif
index dcb7f09972ddd347f775bef66b14a0a3c1082256..64d45931ee8da3ca04a2ca0db8a3ce8902748e21 100644 (file)
--- a/lib/rc2.c
+++ b/lib/rc2.c
@@ -183,33 +183,16 @@ static void rc2_decrypt(void *context, uint8 * outbuf, const uint8 * inbuf)
        do_rc2_decrypt(ctx, outbuf, inbuf);
 }
 
-
+static int disable_p2 = 0;
 
 static gpg_err_code_t
 do_rc2_setkey(void *context, const uint8 * key, unsigned int keylen)
 {
-       static int initialized, disable_p2;
-       static const char *selftest_failed;
        uint i;
        uint8 *S, x;
        RC2_context *ctx = (RC2_context *) context;
        int bits = keylen * 8, len;
 
-       /* Self test is for the plain cipher (with phase 2 stripped)
-        */
-
-       if (!initialized) {
-               initialized = 1;
-               disable_p2 = 1; /* strip phase 2 */
-               selftest_failed = selftest();
-               disable_p2 = 0;
-       }
-       if (selftest_failed) {
-               gnutls_assert();
-               _gnutls_x509_log( selftest_failed);
-               return GPG_ERR_SELFTEST_FAILED;
-       }
-
        if (keylen < 40 / 8)    /* we want at least 40 bits */
                return GPG_ERR_INV_KEYLEN;
 
@@ -352,6 +335,22 @@ static gcry_module_t rc2_40_mod;
 
 int _gnutls_register_rc2_cipher(void)
 {
+const char* selftest_failed;
+
+       /* Self test is for the plain cipher (with phase 2 stripped)
+        */
+       disable_p2 = 1; /* strip phase 2 */
+       selftest_failed = selftest();
+       disable_p2 = 0;
+
+       if (selftest_failed) {
+               gnutls_assert();
+               _gnutls_x509_log( selftest_failed);
+               return GNUTLS_E_INTERNAL_ERROR;
+       }
+
+       /* If self test succeeded then register the cipher.
+        */
        if (gcry_cipher_register(&cipher_spec_rc2,
                                 &_gcry_rc2_40_id, &rc2_40_mod)) {
                gnutls_assert();