Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2005, 2004 Erik Eliasson, Johan Bilien |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | |
| 18 | * In addition, as a special exception, the copyright holders give |
| 19 | * permission to link the code of portions of this program with the |
| 20 | * OpenSSL library under certain conditions as described in each |
| 21 | * individual source file, and distribute linked combinations |
| 22 | * including the two. |
| 23 | * You must obey the GNU General Public License in all respects |
| 24 | * for all of the code used other than OpenSSL. If you modify |
| 25 | * file(s) with this exception, you may extend this exception to your |
| 26 | * version of the file(s), but you are not obligated to do so. If you |
| 27 | * do not wish to do so, delete this exception statement from your |
| 28 | * version. If you delete this exception statement from all source |
| 29 | * files in the program, then also delete it here. |
| 30 | */ |
| 31 | |
| 32 | /** |
| 33 | * @author Erik Eliasson <eliasson@it.kth.se> |
| 34 | * Johan Bilien <jobi@via.ecp.fr> |
| 35 | * Werner Dittmann <Werner.Dittmann@t-online.de> |
| 36 | */ |
| 37 | |
| 38 | #include <openssl/crypto.h> |
| 39 | #include <openssl/sha.h> |
| 40 | |
Alexandre Lision | 7fd5d3d | 2013-12-04 13:06:40 -0500 | [diff] [blame] | 41 | #include <crypto/sha384.h> |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 42 | |
| 43 | void sha384(unsigned char *data, unsigned int data_length, |
| 44 | unsigned char *digest ) |
| 45 | { |
| 46 | SHA384(data, data_length, digest); |
| 47 | } |
| 48 | |
| 49 | void sha384(unsigned char * data_chunks[], |
| 50 | unsigned int data_chunck_length[], |
| 51 | unsigned char *digest) |
| 52 | { |
| 53 | SHA512_CTX ctx; |
| 54 | SHA384_Init( &ctx); |
| 55 | while(*data_chunks) { |
| 56 | SHA384_Update(&ctx, *data_chunks, *data_chunck_length); |
| 57 | data_chunks++; |
| 58 | data_chunck_length++; |
| 59 | } |
| 60 | SHA384_Final(digest, &ctx); |
| 61 | } |
| 62 | |
| 63 | void* createSha384Context() |
| 64 | { |
| 65 | SHA512_CTX* ctx = (SHA512_CTX*)malloc(sizeof (SHA512_CTX)); |
| 66 | SHA384_Init(ctx); |
| 67 | return (void*)ctx; |
| 68 | } |
| 69 | |
| 70 | void closeSha384Context(void* ctx, unsigned char* digest) |
| 71 | { |
| 72 | SHA512_CTX* hd = (SHA512_CTX*)ctx; |
| 73 | |
| 74 | if (digest != NULL) { |
| 75 | SHA384_Final(digest, hd); |
| 76 | } |
| 77 | free(hd); |
| 78 | } |
| 79 | |
| 80 | void sha384Ctx(void* ctx, unsigned char* data, |
| 81 | unsigned int dataLength) |
| 82 | { |
| 83 | SHA512_CTX* hd = (SHA512_CTX*)ctx; |
| 84 | SHA384_Update(hd, data, dataLength); |
| 85 | } |
| 86 | |
| 87 | void sha384Ctx(void* ctx, unsigned char* dataChunks[], |
| 88 | unsigned int dataChunkLength[]) |
| 89 | { |
| 90 | SHA512_CTX* hd = (SHA512_CTX*)ctx; |
| 91 | |
| 92 | while (*dataChunks) { |
| 93 | SHA384_Update (hd, *dataChunks, *dataChunkLength); |
| 94 | dataChunks++; |
| 95 | dataChunkLength++; |
| 96 | } |
| 97 | } |