Add support for PolarSSL 1.1.1
authorMartin Johansson <martin@fatbob.nu>
Sat, 18 Feb 2012 23:35:26 +0000 (00:35 +0100)
committerMartin Johansson <martin@fatbob.nu>
Sat, 18 Feb 2012 23:35:26 +0000 (00:35 +0100)
src/crypt.c
src/ssl.c
src/ssl.h

index 7188c2d92cf084c19de265bf0424c38e5c64603d..5025ba7788dcac745f48689f99962d69cf6e9076 100644 (file)
 #include <string.h>
 #include <arpa/inet.h>
 #include "crypt.h"
+#include "ssl.h"
 
 #ifdef USE_POLARSSL
 #include <polarssl/havege.h>
-#define RAND_bytes(_dst_, _size_) do { \
-       int i; \
-       for (i = 0; i < _size_; i++) { \
-       _dst_[i] = havege_rand(&hs); \
-       } \
- } while (0);
-
 extern havege_state hs;
 #endif
 
index ab953f36b6b876e2d91edae223adf9fc1de0d778..1f2ef6a01deff74fee8871670a9b45384fc0c69d 100644 (file)
--- a/src/ssl.c
+++ b/src/ssl.c
@@ -187,7 +187,7 @@ SSL_handle_t *SSLi_newconnection(int *fd, bool_t *SSLready)
        ssl_set_endpoint(ssl, SSL_IS_SERVER);   
        ssl_set_authmode(ssl, SSL_VERIFY_NONE);
 
-       ssl_set_rng(ssl, havege_rand, &hs);
+       ssl_set_rng(ssl, HAVEGE_RAND, &hs);
        ssl_set_dbg(ssl, pssl_debug, NULL);
        ssl_set_bio(ssl, net_recv, fd, net_send, fd);
 
index 5629c4c6507e468c3738c0abaeb5cbde49408ff6..8aa3f30b96c09056c9e49f41733532cb37ff4cbf 100644 (file)
--- a/src/ssl.h
+++ b/src/ssl.h
 #else
 #if (POLARSSL_VERSION_MAJOR == 0)
        #define POLARSSL_API_V0
+    #define HAVEGE_RAND (havege_rand)
+    #define RAND_bytes(_dst_, _size_) do { \
+           int i; \
+           for (i = 0; i < _size_; i++) { \
+               _dst_[i] = havege_rand(&hs); \
+           } \
+    } while (0)
 #else
        #define POLARSSL_API_V1
+    #if (POLARSSL_VERSION_MINOR >= 1)
+        #define HAVEGE_RAND (havege_random)
+        #define RAND_bytes(_dst_, _size_) do { \
+               havege_random(&hs, _dst_, _size_); \
+               } while (0)
+    #else
+        #define HAVEGE_RAND (havege_rand)
+        #define RAND_bytes(_dst_, _size_) do { \
+                int i; \
+                for (i = 0; i < _size_; i++) { \
+                    _dst_[i] = havege_rand(&hs); \
+                } \
+        } while (0)
+    #endif
 #endif
 #endif