summaryrefslogtreecommitdiffstats
path: root/libraries/Sha/sha256.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/Sha/sha256.h')
-rw-r--r--libraries/Sha/sha256.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/libraries/Sha/sha256.h b/libraries/Sha/sha256.h
new file mode 100644
index 0000000..a29d377
--- /dev/null
+++ b/libraries/Sha/sha256.h
@@ -0,0 +1,60 @@
+/**
+ * Cryptosuite - A cryptographic library for Arduino
+ * Copyright (C) 2010 Peter Knight (Cathedrow)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef Sha256_h
+#define Sha256_h
+
+#include <inttypes.h>
+#include "Print.h"
+
+#define HASH_LENGTH 32
+#define BLOCK_LENGTH 64
+
+union _buffer {
+ uint8_t b[BLOCK_LENGTH];
+ uint32_t w[BLOCK_LENGTH/4];
+};
+union _state {
+ uint8_t b[HASH_LENGTH];
+ uint32_t w[HASH_LENGTH/4];
+};
+
+class Sha256Class : public Print
+{
+ public:
+ void init(void);
+ void initHmac(const uint8_t* secret, int secretLength);
+ uint8_t* result(void);
+ uint8_t* resultHmac(void);
+ virtual void write(uint8_t);
+ using Print::write;
+ private:
+ void pad();
+ void addUncounted(uint8_t data);
+ void hashBlock();
+ uint32_t ror32(uint32_t number, uint8_t bits);
+ _buffer buffer;
+ uint8_t bufferOffset;
+ _state state;
+ uint32_t byteCount;
+ uint8_t keyBuffer[BLOCK_LENGTH];
+ uint8_t innerHash[HASH_LENGTH];
+};
+extern Sha256Class Sha256;
+
+#endif