fixed cipher suite and implemented shutdown/free
[umurmur.git] / src / crypt.c
index 7188c2d92cf084c19de265bf0424c38e5c64603d..ad93dd8bf9c5393f81e748f5c4ad526e63da3f88 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (C) 2009-2011, Martin Johansson <martin@fatbob.nu>
-   Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
+   Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
 
    All rights reserved.
 
 #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);
-
+#ifdef USE_POLARSSL_HAVEGE
 extern havege_state hs;
 #endif
 
@@ -206,7 +199,7 @@ bool_t CryptState_decrypt(cryptState_t *cs, const unsigned char *source, unsigne
        CryptState_ocb_decrypt(cs, source+4, dst, plain_length, cs->decrypt_iv, tag);
 
        if (memcmp(tag, source+1, 3) != 0) {
-               memcpy(cs->decrypt_iv, saveiv, AES_BLOCK_SIZE);         
+               memcpy(cs->decrypt_iv, saveiv, AES_BLOCK_SIZE);
                return false;
        }
        cs->decrypt_history[cs->decrypt_iv[0]] = cs->decrypt_iv[1];
@@ -222,34 +215,6 @@ bool_t CryptState_decrypt(cryptState_t *cs, const unsigned char *source, unsigne
        return true;
 }
 
-#if defined(__LP64__)
-#define BLOCKSIZE 2
-#define SHIFTBITS 63
-typedef uint64_t subblock;
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define SWAPPED(x) (x)
-#else
-#ifdef __x86_64__
-#define SWAPPED(x) ({register uint64_t __out, __in = (x); __asm__("bswap %q0" : "=r"(__out) : "0"(__in)); __out;})
-#else
-#include <byteswap.h>
-#define SWAPPED(x) bswap_64(x)
-#endif
-#endif
-
-#else
-
-#define BLOCKSIZE 4
-#define SHIFTBITS 31
-typedef uint32_t subblock;
-#define SWAPPED(x) htonl(x)
-
-#endif
-
-#define HIGHBIT (1<<SHIFTBITS);
-
-
 static void inline XOR(subblock *dst, const subblock *a, const subblock *b) {
        int i;
        for (i=0;i<BLOCKSIZE;i++) {