fixed big endian bug in md5 hasher
[strongswan.git] / src / libstrongswan / crypto / hashers / hasher.c
index c15f418..7fa6346 100644 (file)
@@ -6,7 +6,8 @@
  */
 
 /*
- * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Copyright (C) 2005-2006 Martin Willi
+ * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
 #include "hasher.h"
 
 #include <crypto/hashers/sha1_hasher.h>
+#include <crypto/hashers/sha2_hasher.h>
 #include <crypto/hashers/md5_hasher.h>
 
-/**
- * String mappings for hash_algorithm_t.
- */
-mapping_t hash_algorithm_m[] = {
-       {HASH_MD2,"HASH_MD2"},
-       {HASH_MD5,"HASH_MD5"},
-       {HASH_SHA1,"HASH_SHA1"},
-       {HASH_SHA256,"HASH_SHA256"},
-       {HASH_SHA384,"HASH_SHA384"},
-       {HASH_SHA512,"HASH_SHA512"},
-       {MAPPING_END, NULL}
-};
+
+ENUM(hash_algorithm_names, HASH_MD2, HASH_SHA512,
+       "HASH_MD2",
+       "HASH_MD5",
+       "HASH_SHA1",
+       "HASH_SHA256",
+       "HASH_SHA384",
+       "HASH_SHA512"
+);
 
 /*
  * Described in header.
@@ -50,6 +49,12 @@ hasher_t *hasher_create(hash_algorithm_t hash_algorithm)
                {
                        return (hasher_t*)sha1_hasher_create();
                }
+               case HASH_SHA256:
+               case HASH_SHA384:
+               case HASH_SHA512:
+               {
+                       return (hasher_t*)sha2_hasher_create(hash_algorithm);
+               }
                case HASH_MD5:
                {
                        return (hasher_t*)md5_hasher_create();