gnutls-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU gnutls branch, master, updated. gnutls_3_0_3-51-g1f86b82


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls_3_0_3-51-g1f86b82
Date: Mon, 03 Oct 2011 15:33:50 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=1f86b82c7a33d37f85ba3bb372bd45d249bed2a3

The branch, master has been updated
       via  1f86b82c7a33d37f85ba3bb372bd45d249bed2a3 (commit)
       via  365d4fb996d165f98f992ecb0d1014058a6c4f4d (commit)
       via  fb3aebc6c20b360d2847af3df08fe198281419c2 (commit)
       via  b7f14ee9f8530af66a6012cd904524f2effe31ef (commit)
       via  97eae5bb258a7cddf2b0b9fe2294bcc36cecaea4 (commit)
       via  6731bedf011610c6b40512ba62feb68edb65067a (commit)
      from  59c61c7a724637706a3f578e01994adbff40c919 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1f86b82c7a33d37f85ba3bb372bd45d249bed2a3
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 17:29:47 2011 +0200

    added an assert

commit 365d4fb996d165f98f992ecb0d1014058a6c4f4d
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 17:14:50 2011 +0200

    doc fixes

commit fb3aebc6c20b360d2847af3df08fe198281419c2
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 17:12:25 2011 +0200

    replaced uint type.

commit b7f14ee9f8530af66a6012cd904524f2effe31ef
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Mon Oct 3 17:12:15 2011 +0200

    fix compilation in windows

commit 97eae5bb258a7cddf2b0b9fe2294bcc36cecaea4
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Oct 1 20:06:10 2011 +0200

    updated text.

commit 6731bedf011610c6b40512ba62feb68edb65067a
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Sat Oct 1 20:04:56 2011 +0200

    Added ability to hash and hmac with VIA padlock.

-----------------------------------------------------------------------

Summary of changes:
 doc/cha-gtls-app.texi               |    5 +-
 doc/cha-library.texi                |   52 +++---
 lib/accelerated/intel/Makefile.am   |    2 +-
 lib/accelerated/intel/aes-padlock.c |  311 +++++++++++++++++++++--------------
 lib/accelerated/intel/aes-padlock.h |    3 +
 lib/accelerated/intel/sha-padlock.c |  294 +++++++++++++++++++++++++++++++++
 lib/gnutls_dtls.c                   |    2 +-
 lib/gnutls_sig.c                    |    2 +-
 lib/gnutls_str.h                    |    6 +
 lib/nettle/egd.c                    |    5 +
 lib/nettle/rnd.c                    |    1 +
 11 files changed, 527 insertions(+), 156 deletions(-)
 create mode 100644 lib/accelerated/intel/sha-padlock.c

diff --git a/doc/cha-gtls-app.texi b/doc/cha-gtls-app.texi
index 5f097f4..8e75628 100644
--- a/doc/cha-gtls-app.texi
+++ b/doc/cha-gtls-app.texi
@@ -278,8 +278,9 @@ to generate a secret key that is used to sign a 
address@hidden key of 128 bit
 That cookie is sent to the client using @funcref{gnutls_dtls_cookie_send}, and 
 the client must reply using the correct cookie. The server side
 should verify the initial message sent by client using 
@funcref{gnutls_dtls_cookie_verify}.
-If successful a the session should be initialization and associated with
-the cookie using @funcref{gnutls_dtls_prestate_set}.
+If successful the session should be initialized and associated with
+the cookie using @funcref{gnutls_dtls_prestate_set}, before proceeding to
+the handshake.
 
 
@showfuncD{gnutls_key_generate,gnutls_dtls_cookie_send,gnutls_dtls_cookie_verify,gnutls_dtls_prestate_set}
 
diff --git a/doc/cha-library.texi b/doc/cha-library.texi
index 31f9558..78598bf 100644
--- a/doc/cha-library.texi
+++ b/doc/cha-library.texi
@@ -125,29 +125,23 @@ finished using @acronym{GnuTLS}.
 @caption{High level design of GnuTLS.}
 @end float
 
-The credentials structure is used by some authentication methods, such
-as certificate authentication.  A
-credentials structure may contain certificates, private keys,
-temporary parameters for Diffie-Hellman or RSA key exchange, and other
-stuff that may be shared between several TLS sessions.
-
-This structure should be initialized using the appropriate
-initialization functions. For example an application which uses
-certificate authentication would probably initialize the credentials,
-using the appropriate functions, and put its trusted certificates in
-this structure. The next step is to associate the credentials
-structure with each @acronym{TLS} session.
-
-A @acronym{GnuTLS} session contains all the required information for a
-session to handle one secure connection. This session calls directly
-to the transport layer functions, in order to communicate with the
-peer.  Every session has a unique session ID shared with the peer.
-
-Since TLS sessions can be resumed, servers would probably need a
+The credentials structures are used by the authentication methods, such
+as certificate authentication. They store certificates, privates keys,
+and other information that is needed to prove the identity to the peer,
+and/or verify the indentity of the peer. The information stored in
+the credentials structures is initialized once and then can be 
+shared by many @acronym{TLS} sessions.
+
+A @acronym{GnuTLS} session contains all the required information
+to handle one secure connection. The session communicates with the
+peers using the provided functions of the transport layer.
+Every session has a unique session ID shared with the peer.
+
+Since TLS sessions can be resumed, servers need a
 database back-end to hold the session's parameters.  Every
 @acronym{GnuTLS} session after a successful handshake calls the
-appropriate back-end function (see @ref{resume}, for information on
-initialization) to store the newly negotiated session. The session
+appropriate back-end function (see @ref{resume})
+to store the newly negotiated session. The session
 database is examined by the server just after having received the
 client address@hidden first message in a @acronym{TLS} handshake},
 and if the session ID sent by the client, matches a stored session,
@@ -202,15 +196,23 @@ or other information about the peer involved.
 @node Thread safety
 @section Thread safety
 
-Although the @acronym{GnuTLS} library is thread safe by design, some
-parts of the cryptographic back-end, such as the random generator, are not.
-Applications can either call @funcref{gnutls_global_init} which will use the 
default
+The @acronym{GnuTLS} library is thread safe by design, meaning that
+objects of the library such as TLS sessions, can be safely divided across
+threads as long as a single thread accesses a single object. This is
+sufficient to support a server which handles several sessions per thread.
+If, however, an object needs to be shared across threads then access must be 
+protected with a mutex. Read-only access to objects, for example the
+credentials holding structures (see @ref{Authentication methods}), is also 
thread-safe. 
+
+The random generator of the cryptographic back-end, is not thread safe and 
requires
+mutex locks which are setup by @acronym{GnuTLS}.
+Applications can either call @funcref{gnutls_global_init} which will 
initialize the default
 operating system provided locks (i.e. @code{pthreads} on GNU/Linux and
 @code{CriticalSection} on Windows), or specify manually the locking system 
using 
 the function @funcref{gnutls_global_set_mutex} before calling 
@funcref{gnutls_global_init}. 
 Setting manually mutexes is recommended
 only to applications that have full control of the underlying libraries. If 
this
-is not the case, the use of the operating system defaults is recommended. An 
of 
+is not the case, the use of the operating system defaults is recommended. An 
example of 
 native thread usage is shown below.
 
 @example
diff --git a/lib/accelerated/intel/Makefile.am 
b/lib/accelerated/intel/Makefile.am
index cbb00e9..315c277 100644
--- a/lib/accelerated/intel/Makefile.am
+++ b/lib/accelerated/intel/Makefile.am
@@ -34,7 +34,7 @@ EXTRA_DIST = README license.txt
 
 noinst_LTLIBRARIES = libintel.la
 
-libintel_la_SOURCES = aes-x86.c aes-padlock.c aes-gcm-padlock.c aes-padlock.h 
aes-x86.h x86.h
+libintel_la_SOURCES = sha-padlock.c aes-x86.c aes-padlock.c aes-gcm-padlock.c 
aes-padlock.h aes-x86.h x86.h
 
 if ASM_X86_64
 AM_CPPFLAGS += -DASM_X86_64
diff --git a/lib/accelerated/intel/aes-padlock.c 
b/lib/accelerated/intel/aes-padlock.c
index 881ab28..4e7b8cc 100644
--- a/lib/accelerated/intel/aes-padlock.c
+++ b/lib/accelerated/intel/aes-padlock.c
@@ -37,200 +37,259 @@
 #include <aes-padlock.h>
 
 static int
-aes_cipher_init(gnutls_cipher_algorithm_t algorithm, void **_ctx, int enc)
+aes_cipher_init (gnutls_cipher_algorithm_t algorithm, void **_ctx, int enc)
 {
-    /* we use key size to distinguish */
-    if (algorithm != GNUTLS_CIPHER_AES_128_CBC
-        && algorithm != GNUTLS_CIPHER_AES_192_CBC
-        && algorithm != GNUTLS_CIPHER_AES_256_CBC)
-        return GNUTLS_E_INVALID_REQUEST;
-
-    *_ctx = gnutls_calloc(1, sizeof(struct padlock_ctx));
-    if (*_ctx == NULL) {
-        gnutls_assert();
-        return GNUTLS_E_MEMORY_ERROR;
+  /* we use key size to distinguish */
+  if (algorithm != GNUTLS_CIPHER_AES_128_CBC
+      && algorithm != GNUTLS_CIPHER_AES_192_CBC
+      && algorithm != GNUTLS_CIPHER_AES_256_CBC)
+    return GNUTLS_E_INVALID_REQUEST;
+
+  *_ctx = gnutls_calloc (1, sizeof (struct padlock_ctx));
+  if (*_ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
     }
 
-    ((struct padlock_ctx *) (*_ctx))->enc = enc;
-    return 0;
+  ((struct padlock_ctx *) (*_ctx))->enc = enc;
+  return 0;
 }
 
-int padlock_aes_cipher_setkey(void *_ctx, const void *userkey, size_t keysize)
+int
+padlock_aes_cipher_setkey (void *_ctx, const void *userkey, size_t keysize)
 {
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pce;
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pce;
 #ifdef HAVE_LIBNETTLE
-    struct aes_ctx nc;
+  struct aes_ctx nc;
 #endif
 
-    memset(_ctx, 0, sizeof(struct padlock_cipher_data));
+  memset (_ctx, 0, sizeof (struct padlock_cipher_data));
 
-    pce = ALIGN16(&ctx->expanded_key);
+  pce = ALIGN16 (&ctx->expanded_key);
 
-    pce->cword.b.encdec = (ctx->enc == 0);
+  pce->cword.b.encdec = (ctx->enc == 0);
 
-    switch (keysize) {
+  switch (keysize)
+    {
     case 16:
-        pce->cword.b.ksize = 0;
-        pce->cword.b.rounds = 10;
-        memcpy(pce->ks.rd_key, userkey, 16);
-        pce->cword.b.keygen = 0;
-        break;
+      pce->cword.b.ksize = 0;
+      pce->cword.b.rounds = 10;
+      memcpy (pce->ks.rd_key, userkey, 16);
+      pce->cword.b.keygen = 0;
+      break;
 #ifdef HAVE_LIBNETTLE
     case 24:
-        pce->cword.b.ksize = 1;
-        pce->cword.b.rounds = 12;
-        goto common_24_32;
+      pce->cword.b.ksize = 1;
+      pce->cword.b.rounds = 12;
+      goto common_24_32;
     case 32:
-        pce->cword.b.ksize = 2;
-        pce->cword.b.rounds = 14;
-      common_24_32:
-        /* expand key using nettle */
-        if (ctx->enc)
-            aes_set_encrypt_key(&nc, keysize, userkey);
-        else 
-            aes_set_decrypt_key(&nc, keysize, userkey);
-
-        memcpy(pce->ks.rd_key, nc.keys, sizeof(nc.keys));
-        pce->ks.rounds = nc.nrounds;
-
-        pce->cword.b.keygen = 1;
-        break;
+      pce->cword.b.ksize = 2;
+      pce->cword.b.rounds = 14;
+    common_24_32:
+      /* expand key using nettle */
+      if (ctx->enc)
+        aes_set_encrypt_key (&nc, keysize, userkey);
+      else
+        aes_set_decrypt_key (&nc, keysize, userkey);
+
+      memcpy (pce->ks.rd_key, nc.keys, sizeof (nc.keys));
+      pce->ks.rounds = nc.nrounds;
+
+      pce->cword.b.keygen = 1;
+      break;
 #endif
     default:
-        return gnutls_assert_val(GNUTLS_E_ENCRYPTION_FAILED);
+      return gnutls_assert_val (GNUTLS_E_ENCRYPTION_FAILED);
     }
 
-    padlock_reload_key();
+  padlock_reload_key ();
 
-    return 0;
+  return 0;
 }
 
-static int aes_setiv(void *_ctx, const void *iv, size_t iv_size)
+static int
+aes_setiv (void *_ctx, const void *iv, size_t iv_size)
 {
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pce;
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pce;
 
-    pce = ALIGN16(&ctx->expanded_key);
+  pce = ALIGN16 (&ctx->expanded_key);
 
-    memcpy(pce->iv, iv, 16);
+  memcpy (pce->iv, iv, 16);
 
-    return 0;
+  return 0;
 }
 
 static int
-padlock_aes_cbc_encrypt(void *_ctx, const void *src, size_t src_size,
-                    void *dst, size_t dst_size)
+padlock_aes_cbc_encrypt (void *_ctx, const void *src, size_t src_size,
+                         void *dst, size_t dst_size)
 {
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pce;
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pce;
 
-    pce = ALIGN16(&ctx->expanded_key);
+  pce = ALIGN16 (&ctx->expanded_key);
 
-    padlock_cbc_encrypt(dst, src, pce, src_size);
+  padlock_cbc_encrypt (dst, src, pce, src_size);
 
-    return 0;
+  return 0;
 }
 
 
 static int
-padlock_aes_cbc_decrypt(void *_ctx, const void *src, size_t src_size,
-                    void *dst, size_t dst_size)
+padlock_aes_cbc_decrypt (void *_ctx, const void *src, size_t src_size,
+                         void *dst, size_t dst_size)
 {
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pcd;
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pcd;
 
-    pcd = ALIGN16(&ctx->expanded_key);
+  pcd = ALIGN16 (&ctx->expanded_key);
 
-    padlock_cbc_encrypt(dst, src, pcd, src_size);
+  padlock_cbc_encrypt (dst, src, pcd, src_size);
 
-    return 0;
+  return 0;
 }
 
-static void aes_deinit(void *_ctx)
+static void
+aes_deinit (void *_ctx)
 {
-    gnutls_free(_ctx);
+  gnutls_free (_ctx);
 }
 
 static const gnutls_crypto_cipher_st aes_padlock_struct = {
-    .init = aes_cipher_init,
-    .setkey = padlock_aes_cipher_setkey,
-    .setiv = aes_setiv,
-    .encrypt = padlock_aes_cbc_encrypt,
-    .decrypt = padlock_aes_cbc_decrypt,
-    .deinit = aes_deinit,
+  .init = aes_cipher_init,
+  .setkey = padlock_aes_cipher_setkey,
+  .setiv = aes_setiv,
+  .encrypt = padlock_aes_cbc_encrypt,
+  .decrypt = padlock_aes_cbc_decrypt,
+  .deinit = aes_deinit,
 };
 
-static int check_padlock(void)
+static int
+check_padlock (void)
+{
+  unsigned int edx = padlock_capability ();
+
+  return ((edx & (0x3 << 6)) == (0x3 << 6));
+}
+
+static int
+check_phe (void)
 {
-    unsigned int edx = padlock_capability();
+  unsigned int edx = padlock_capability ();
 
-    return ((edx & (0x3 << 6)) == (0x3 << 6));
+  return ((edx & (0x3 << 10)) == (0x3 << 10));
 }
 
-static unsigned check_via(void)
+static unsigned
+check_via (void)
 {
-    unsigned int a, b, c, d;
-    _gnutls_cpuid(0, &a, &b, &c, &d);
+  unsigned int a, b, c, d;
+  _gnutls_cpuid (0, &a, &b, &c, &d);
 
-    if ((memcmp(&b, "Cent", 4) == 0 &&
-         memcmp(&d, "aurH", 4) == 0 && memcmp(&c, "auls", 4) == 0)) {
-        return 1;
+  if ((memcmp (&b, "Cent", 4) == 0 &&
+       memcmp (&d, "aurH", 4) == 0 && memcmp (&c, "auls", 4) == 0))
+    {
+      return 1;
     }
 
-    return 0;
+  return 0;
 }
 
-void register_padlock_crypto(void)
+void
+register_padlock_crypto (void)
 {
-    int ret;
-
-    /* Only enable the 32-bit padlock variant, until
-     * the 64-bit code is tested.
-     */
-    if (check_via() == 0)
-        return;
-
-    if (check_padlock()) {
-        _gnutls_debug_log("Padlock AES accelerator was detected\n");
-        ret =
-            gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_128_CBC,
-                                                 80, &aes_padlock_struct);
-        if (ret < 0) {
-            gnutls_assert();
+  int ret;
+
+  /* Only enable the 32-bit padlock variant, until
+   * the 64-bit code is tested.
+   */
+  if (check_via () == 0)
+    return;
+
+  if (check_padlock ())
+    {
+      _gnutls_debug_log ("Padlock AES accelerator was detected\n");
+      ret =
+          gnutls_crypto_single_cipher_register
+          (GNUTLS_CIPHER_AES_128_CBC, 80, &aes_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
         }
 
-        /* register GCM ciphers */
-        ret =
-            gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_128_GCM,
-                                                 80,
-                                                 &aes_gcm_padlock_struct);
-        if (ret < 0) {
-            gnutls_assert();
+      /* register GCM ciphers */
+      ret =
+          gnutls_crypto_single_cipher_register
+          (GNUTLS_CIPHER_AES_128_GCM, 80, &aes_gcm_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
         }
-    }
 #ifdef HAVE_LIBNETTLE
-    ret =
-        gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_192_CBC,
-                                             80, &aes_padlock_struct);
-    if (ret < 0) {
-        gnutls_assert();
-    }
+      ret =
+          gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_192_CBC,
+                                                80, &aes_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
 
-    ret =
-        gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_256_CBC,
-                                             80, &aes_padlock_struct);
-    if (ret < 0) {
-        gnutls_assert();
+      ret =
+          gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_256_CBC,
+                                                80, &aes_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+          gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_256_GCM,
+                                                80,
+                                                &aes_gcm_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+#endif
     }
 
-    ret =
-        gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_256_GCM,
-                                             80, &aes_gcm_padlock_struct);
-    if (ret < 0) {
-        gnutls_assert();
+  if (check_phe())
+    {
+      ret =
+          gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA1,
+                                             80, &sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+          gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA256,
+                                             80, &sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+          gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA1,
+                                             80, &hmac_sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+          gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA256,
+                                             80, &hmac_sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
     }
-#endif
 
-    return;
+  return;
 }
diff --git a/lib/accelerated/intel/aes-padlock.h 
b/lib/accelerated/intel/aes-padlock.h
index d15a6b9..c3798d6 100644
--- a/lib/accelerated/intel/aes-padlock.h
+++ b/lib/accelerated/intel/aes-padlock.h
@@ -2,6 +2,7 @@
 # define AES_PADLOCK_H
 
 #include <gnutls_int.h>
+#include <aes-x86.h>
 
 struct padlock_cipher_data {
     unsigned char iv[16];       /* Initialization vector */
@@ -27,6 +28,8 @@ struct padlock_ctx {
 };
 
 extern const gnutls_crypto_cipher_st aes_gcm_padlock_struct;
+extern const gnutls_crypto_mac_st hmac_sha_padlock_struct;
+extern const gnutls_crypto_digest_st sha_padlock_struct;
 
 int padlock_aes_cipher_setkey(void *_ctx, const void *userkey, size_t keysize);
 
diff --git a/lib/accelerated/intel/sha-padlock.c 
b/lib/accelerated/intel/sha-padlock.c
new file mode 100644
index 0000000..8c707fa
--- /dev/null
+++ b/lib/accelerated/intel/sha-padlock.c
@@ -0,0 +1,294 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include <gnutls_int.h>
+#include <gnutls_hash_int.h>
+#include <gnutls_errors.h>
+#include <nettle/sha.h>
+#include <aes-padlock.h>
+
+/* This enables padlock's SHA capabilities for HMAC operations. 
+ * Unfortunately due to padlock's inner workings only the final hash
+ * of the HMAC() is being hardware accelerated. The rest is plain
+ * software.
+ */
+
+typedef void (*update_func) (void *, unsigned, const uint8_t *);
+typedef void (*digest_func) (void *, unsigned, uint8_t *);
+typedef void (*padlock_hash_func) (void* digest, const void* src, size_t len);
+
+#define SHA_BLOCK_SIZE 64
+#define MAX_SHA_DIGEST_SIZE 32
+#define IPAD 0x36
+#define OPAD 0x5c
+
+struct padlock_hmac_ctx
+{
+  gnutls_buffer_st buf;
+
+  gnutls_mac_algorithm_t algo;
+  size_t length;
+
+  unsigned char ipad[SHA_BLOCK_SIZE];
+  unsigned char opad[SHA_BLOCK_SIZE];
+};
+
+static int
+wrap_padlock_hmac_init (gnutls_mac_algorithm_t algo, void **_ctx)
+{
+  struct padlock_hmac_ctx *ctx;
+  
+  if (algo != GNUTLS_MAC_SHA1 && algo != GNUTLS_MAC_SHA256)
+    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
+  ctx = gnutls_calloc (1, sizeof (struct padlock_hmac_ctx));
+  if (ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ctx->algo = algo;
+  _gnutls_buffer_init(&ctx->buf);
+
+  *_ctx = ctx;
+
+  return 0;
+}
+
+
+static int
+wrap_padlock_hmac_setkey (void *_ctx, const void *key, size_t key_size)
+{
+  struct padlock_hmac_ctx *ctx = _ctx;
+  padlock_hash_func hash;
+  unsigned char hkey[MAX_SHA_DIGEST_SIZE];
+
+  if (key_size > SHA_BLOCK_SIZE) 
+    {
+      if (ctx->algo == GNUTLS_MAC_SHA1)
+        hash = padlock_sha1_oneshot;
+      else
+        hash = padlock_sha256_oneshot;
+
+      hash(hkey, key, key_size);
+      key = hkey;
+      key_size = _gnutls_hmac_get_algo_len(ctx->algo);
+    }
+
+  memset (ctx->ipad, IPAD, SHA_BLOCK_SIZE);
+  memxor (ctx->ipad, key, key_size);
+
+  _gnutls_buffer_append_data( &ctx->buf, ctx->ipad, SHA_BLOCK_SIZE);
+
+  return GNUTLS_E_SUCCESS;
+}
+
+static void
+wrap_padlock_hmac_reset (void *_ctx)
+{
+  struct padlock_hmac_ctx *ctx = _ctx;
+
+  _gnutls_buffer_reset(&ctx->buf);
+  _gnutls_buffer_append_data( &ctx->buf, ctx->ipad, SHA_BLOCK_SIZE);
+}
+
+static int
+wrap_padlock_hmac_update (void *_ctx, const void *text, size_t textsize)
+{
+  struct padlock_hmac_ctx *ctx = _ctx;
+
+  _gnutls_buffer_append_data( &ctx->buf, text, textsize);
+
+  return GNUTLS_E_SUCCESS;
+}
+
+static void
+wrap_padlock_hmac_deinit (void *_ctx)
+{
+  struct padlock_hmac_ctx *ctx = _ctx;
+
+  _gnutls_buffer_clear(&ctx->buf);
+  gnutls_free (ctx);
+}
+
+static int
+wrap_padlock_hmac_output (void *_ctx, void *digest, size_t digestsize)
+{
+  struct padlock_hmac_ctx *ctx = _ctx;
+  unsigned char pad[SHA_BLOCK_SIZE + MAX_SHA_DIGEST_SIZE];
+  padlock_hash_func hash;
+
+  if (ctx->algo == GNUTLS_MAC_SHA1)
+    hash = padlock_sha1_oneshot;
+  else
+    hash = padlock_sha256_oneshot;
+
+  if (digestsize < ctx->length)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_SHORT_MEMORY_BUFFER;
+    }
+
+  memcpy (pad, ctx->opad, SHA_BLOCK_SIZE);
+  hash(&pad[SHA_BLOCK_SIZE], ctx->buf.data, ctx->buf.length);
+
+  hash(digest, pad, ctx->length + SHA_BLOCK_SIZE);
+
+  return 0;
+}
+
+
+static int wrap_padlock_hmac_fast(gnutls_mac_algorithm_t algo, 
+  const void *key, size_t key_size, const void* text, size_t text_size, 
+  void* digest)
+{
+  unsigned char *pad;
+  unsigned char pad2[SHA_BLOCK_SIZE + MAX_SHA_DIGEST_SIZE];
+  unsigned char hkey[MAX_SHA_DIGEST_SIZE];
+  padlock_hash_func hash;
+
+  if (algo == GNUTLS_MAC_SHA1)
+    hash = padlock_sha1_oneshot;
+  else
+    hash = padlock_sha256_oneshot;
+
+  if (key_size > SHA_BLOCK_SIZE) 
+    {
+      hash(hkey, key, key_size);
+      key = hkey;
+      key_size = _gnutls_hmac_get_algo_len(algo);
+    }
+
+  pad = gnutls_malloc(text_size + SHA_BLOCK_SIZE);
+  if (pad == NULL)
+    return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
+  
+  memset (pad, IPAD, SHA_BLOCK_SIZE);
+  memxor (pad, key, key_size);
+  
+  memcpy (&pad[SHA_BLOCK_SIZE], text, text_size);
+  
+  hash(&pad2[SHA_BLOCK_SIZE], pad, text_size + SHA_BLOCK_SIZE);
+  
+  gnutls_free(pad);
+
+  memset (pad2, OPAD, SHA_BLOCK_SIZE);
+  memxor (pad2, key, key_size);
+  
+  hash(digest, pad2, SHA1_DIGEST_SIZE + SHA_BLOCK_SIZE);
+  
+  return 0;
+}
+
+const gnutls_crypto_mac_st hmac_sha_padlock_struct = {
+  .init = wrap_padlock_hmac_init,
+  .setkey = wrap_padlock_hmac_setkey,
+  .hash = wrap_padlock_hmac_update,
+  .reset = wrap_padlock_hmac_reset,
+  .output = wrap_padlock_hmac_output,
+  .deinit = wrap_padlock_hmac_deinit,
+  .fast = wrap_padlock_hmac_fast
+};
+
+
+struct padlock_hash_ctx
+{
+  gnutls_buffer_st buf;
+  gnutls_digest_algorithm_t algo;
+  size_t length; /* output length */
+};
+
+static int
+wrap_padlock_hash_init (gnutls_digest_algorithm_t algo, void **_ctx)
+{
+  struct padlock_hash_ctx *ctx;
+  
+  if (algo != GNUTLS_DIG_SHA1 && algo != GNUTLS_DIG_SHA256)
+    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
+  ctx = gnutls_calloc (1, sizeof (struct padlock_hash_ctx));
+  if (ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ctx->algo = algo;
+  _gnutls_buffer_init(&ctx->buf);
+
+  *_ctx = ctx;
+
+  return 0;
+}
+
+static int
+wrap_padlock_hash_update (void *_ctx, const void *text, size_t textsize)
+{
+  struct padlock_hash_ctx *ctx = _ctx;
+
+  _gnutls_buffer_append_data( &ctx->buf, text, textsize);
+
+  return GNUTLS_E_SUCCESS;
+}
+
+static void
+wrap_padlock_hash_deinit (void *_ctx)
+{
+  struct padlock_hash_ctx *ctx = _ctx;
+
+  _gnutls_buffer_clear(&ctx->buf);
+  gnutls_free (ctx);
+}
+
+static int
+wrap_padlock_hash_output (void *_ctx, void *digest, size_t digestsize)
+{
+  struct padlock_hash_ctx *ctx = _ctx;
+
+  if (ctx->algo == GNUTLS_DIG_SHA1)
+    padlock_sha1_oneshot (digest, ctx->buf.data, ctx->buf.length);
+  else
+    padlock_sha256_oneshot (digest, ctx->buf.data, ctx->buf.length);
+
+  return 0;
+}
+
+static int wrap_padlock_hash_fast(gnutls_digest_algorithm_t algo, 
+  const void* text, size_t text_size, 
+  void* digest)
+{
+  if (algo == GNUTLS_DIG_SHA1)
+    padlock_sha1_oneshot (digest, text, text_size);
+  else
+    padlock_sha256_oneshot (digest, text, text_size);
+  
+  return 0;
+}
+
+const gnutls_crypto_digest_st sha_padlock_struct = {
+  .init = wrap_padlock_hash_init,
+  .hash = wrap_padlock_hash_update,
+  .output = wrap_padlock_hash_output,
+  .deinit = wrap_padlock_hash_deinit,
+  .fast = wrap_padlock_hash_fast
+};
diff --git a/lib/gnutls_dtls.c b/lib/gnutls_dtls.c
index 7f4bab6..16a6179 100644
--- a/lib/gnutls_dtls.c
+++ b/lib/gnutls_dtls.c
@@ -45,7 +45,7 @@ transmit_message (gnutls_session_t session,
   opaque *data, *mtu_data;
   int ret = 0;
   unsigned int offset, frag_len, data_size;
-  const uint mtu = gnutls_dtls_get_data_mtu(session) - 
DTLS_HANDSHAKE_HEADER_SIZE;
+  const unsigned int mtu = gnutls_dtls_get_data_mtu(session) - 
DTLS_HANDSHAKE_HEADER_SIZE;
 
   if (bufel->type == GNUTLS_CHANGE_CIPHER_SPEC)
     {
diff --git a/lib/gnutls_sig.c b/lib/gnutls_sig.c
index 5500148..546153b 100644
--- a/lib/gnutls_sig.c
+++ b/lib/gnutls_sig.c
@@ -229,7 +229,7 @@ sign_tls_hash (gnutls_session_t session, 
gnutls_digest_algorithm_t hash_algo,
       if (!pkey)
         {
           if (!session->internals.sign_func)
-            return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
+            return gnutls_assert_val(GNUTLS_E_INSUFFICIENT_CREDENTIALS);
 
           return (*session->internals.sign_func)
             (session, session->internals.sign_func_userdata,
diff --git a/lib/gnutls_str.h b/lib/gnutls_str.h
index dbf299c..3b6562e 100644
--- a/lib/gnutls_str.h
+++ b/lib/gnutls_str.h
@@ -41,6 +41,12 @@ typedef struct
 
 void _gnutls_buffer_init (gnutls_buffer_st *);
 void _gnutls_buffer_clear (gnutls_buffer_st *);
+inline static void _gnutls_buffer_reset (gnutls_buffer_st * buf)
+{
+  buf->data = buf->allocd;
+  buf->length = 0;
+}
+
 int _gnutls_buffer_resize (gnutls_buffer_st *, size_t new_size);
 
 int _gnutls_buffer_append_str (gnutls_buffer_st *, const char *str);
diff --git a/lib/nettle/egd.c b/lib/nettle/egd.c
index f472aed..1b67e42 100644
--- a/lib/nettle/egd.c
+++ b/lib/nettle/egd.c
@@ -19,6 +19,9 @@
  */
 
 #include <config.h>
+
+#ifndef _WIN32
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -268,3 +271,5 @@ restart:
 
   return _length;               /* success */
 }
+
+#endif
diff --git a/lib/nettle/rnd.c b/lib/nettle/rnd.c
index b3e18ac..b01ac08 100644
--- a/lib/nettle/rnd.c
+++ b/lib/nettle/rnd.c
@@ -55,6 +55,7 @@ static void *rnd_mutex;
 #ifdef _WIN32
 
 #include <windows.h>
+#include <wincrypt.h>
 
 #define DEVICE_READ_SIZE 16
 #define DEVICE_READ_SIZE_MAX 32


hooks/post-receive
-- 
GNU gnutls



reply via email to

[Prev in Thread] Current Thread [Next in Thread]