summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2003-08-13 10:25:46 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2003-08-13 10:25:46 +0000
commitb45f15c3f856a581a66d052ee6743aae84fc8310 (patch)
treec2320338fd38919b79108073bbb2808e29ce03db
parent43b44f0068092f72010627e9c0746f61b354808f (diff)
downloadgnutls-b45f15c3f856a581a66d052ee6743aae84fc8310.tar.gz
RC2 was made reentrant. The stddef.h is now included if found.
-rw-r--r--configure.in2
-rw-r--r--lib/defines.h4
-rw-r--r--lib/rc2.c35
3 files changed, 22 insertions, 19 deletions
diff --git a/configure.in b/configure.in
index 5ad3f1a938..7f7bf916d9 100644
--- a/configure.in
+++ b/configure.in
@@ -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,,)
diff --git a/lib/defines.h b/lib/defines.h
index 4524ade3ca..171f7c1a32 100644
--- a/lib/defines.h
+++ b/lib/defines.h
@@ -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
diff --git a/lib/rc2.c b/lib/rc2.c
index dcb7f09972..64d45931ee 100644
--- 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();