aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pk_pad/mgf1
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pk_pad/mgf1')
-rw-r--r--src/lib/pk_pad/mgf1/info.txt5
-rw-r--r--src/lib/pk_pad/mgf1/mgf1.cpp36
-rw-r--r--src/lib/pk_pad/mgf1/mgf1.h25
3 files changed, 66 insertions, 0 deletions
diff --git a/src/lib/pk_pad/mgf1/info.txt b/src/lib/pk_pad/mgf1/info.txt
new file mode 100644
index 000000000..65d471c8a
--- /dev/null
+++ b/src/lib/pk_pad/mgf1/info.txt
@@ -0,0 +1,5 @@
+define MGF1 20140118
+
+<requires>
+hash
+</requires>
diff --git a/src/lib/pk_pad/mgf1/mgf1.cpp b/src/lib/pk_pad/mgf1/mgf1.cpp
new file mode 100644
index 000000000..eae2fed59
--- /dev/null
+++ b/src/lib/pk_pad/mgf1/mgf1.cpp
@@ -0,0 +1,36 @@
+/*
+* MGF1
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/mgf1.h>
+#include <botan/exceptn.h>
+#include <botan/internal/xor_buf.h>
+#include <algorithm>
+
+namespace Botan {
+
+void mgf1_mask(HashFunction& hash,
+ const byte in[], size_t in_len,
+ byte out[], size_t out_len)
+ {
+ u32bit counter = 0;
+
+ while(out_len)
+ {
+ hash.update(in, in_len);
+ hash.update_be(counter);
+ secure_vector<byte> buffer = hash.final();
+
+ size_t xored = std::min<size_t>(buffer.size(), out_len);
+ xor_buf(out, &buffer[0], xored);
+ out += xored;
+ out_len -= xored;
+
+ ++counter;
+ }
+ }
+
+}
diff --git a/src/lib/pk_pad/mgf1/mgf1.h b/src/lib/pk_pad/mgf1/mgf1.h
new file mode 100644
index 000000000..bceaf0857
--- /dev/null
+++ b/src/lib/pk_pad/mgf1/mgf1.h
@@ -0,0 +1,25 @@
+/*
+* MGF1
+* (C) 1999-2007,2014 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_MGF1_H__
+#define BOTAN_MGF1_H__
+
+#include <botan/kdf.h>
+#include <botan/hash.h>
+
+namespace Botan {
+
+/**
+* MGF1 from PKCS #1 v2.0
+*/
+void mgf1_mask(HashFunction& hash,
+ const byte in[], size_t in_len,
+ byte out[], size_t out_len);
+
+}
+
+#endif