aboutsummaryrefslogtreecommitdiff
path: root/src/stable/sha1.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/stable/sha1.h')
-rw-r--r--src/stable/sha1.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/stable/sha1.h b/src/stable/sha1.h
new file mode 100644
index 0000000..1b7f6df
--- /dev/null
+++ b/src/stable/sha1.h
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef SHA1_H
9#define SHA1_H
10
11#include <stdint.h>
12#include "bu/cryptohash.h"
13
14namespace Bu
15{
16 /**
17 * Calculates SHA-1 sums. This is based strongly on code from Michael D.
18 * Leonhard who released his code under the terms of the MIT license,
19 * thank you! Check out his website http://tamale.net he has a lot of
20 * cool stuff there.
21 */
22 class Sha1 : public CryptoHash
23 {
24 public:
25 Sha1();
26 virtual ~Sha1();
27
28 virtual void reset();
29 virtual void setSalt( const Bu::String &sSalt );
30 virtual void addData( const void *sData, int iSize );
31 using CryptoHash::addData;
32 virtual String getResult();
33 virtual void writeResult( Stream &sOut );
34
35 void update( const char* data, int num );
36 unsigned char* getDigest();
37
38 // utility methods
39
40 private:
41 static uint32_t lrot( uint32_t x, int bits );
42 static void toBigEndian( uint32_t in, unsigned char* out );
43 void process();
44
45 private:
46 uint32_t uH0, uH1, uH2, uH3, uH4;
47 unsigned char uBytes[64];
48 int iUnprocessedBytes;
49 uint32_t uTotalBytes;
50 };
51};
52
53#endif