security: add support for SHA-3
Requires openssl >= 1.1.1-pre1
Change-Id: I8d91ca30425129694f3b0fc40daa891b58ded065
diff --git a/src/security/detail/openssl-helper.cpp b/src/security/detail/openssl-helper.cpp
index 92ec501..b5c9e5e 100644
--- a/src/security/detail/openssl-helper.cpp
+++ b/src/security/detail/openssl-helper.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -43,6 +43,16 @@
case DigestAlgorithm::BLAKE2S_256:
return EVP_blake2s256();
#endif
+#if OPENSSL_VERSION_NUMBER >= 0x10101001L
+ case DigestAlgorithm::SHA3_224:
+ return EVP_sha3_224();
+ case DigestAlgorithm::SHA3_256:
+ return EVP_sha3_256();
+ case DigestAlgorithm::SHA3_384:
+ return EVP_sha3_384();
+ case DigestAlgorithm::SHA3_512:
+ return EVP_sha3_512();
+#endif
default:
return nullptr;
}
diff --git a/src/security/detail/openssl.hpp b/src/security/detail/openssl.hpp
index 99d20cb..252d370 100644
--- a/src/security/detail/openssl.hpp
+++ b/src/security/detail/openssl.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -33,7 +33,6 @@
#include <openssl/ec.h>
#include <openssl/err.h>
#include <openssl/evp.h>
-#include <openssl/hmac.h>
#include <openssl/pem.h>
#include <openssl/rand.h>
#include <openssl/rsa.h>
diff --git a/src/security/security-common.cpp b/src/security/security-common.cpp
index 5e5fa31..1d0d4f2 100644
--- a/src/security/security-common.cpp
+++ b/src/security/security-common.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -89,6 +89,14 @@
return os << "BLAKE2b-512";
case DigestAlgorithm::BLAKE2S_256:
return os << "BLAKE2s-256";
+ case DigestAlgorithm::SHA3_224:
+ return os << "SHA3-224";
+ case DigestAlgorithm::SHA3_256:
+ return os << "SHA3-256";
+ case DigestAlgorithm::SHA3_384:
+ return os << "SHA3-384";
+ case DigestAlgorithm::SHA3_512:
+ return os << "SHA3-512";
}
return os << static_cast<int>(algorithm);
}
diff --git a/src/security/security-common.hpp b/src/security/security-common.hpp
index 9685dc3..c2fa8f4 100644
--- a/src/security/security-common.hpp
+++ b/src/security/security-common.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -110,6 +110,10 @@
SHA512 = 4,
BLAKE2B_512 = 10,
BLAKE2S_256 = 11,
+ SHA3_224 = 20,
+ SHA3_256 = 21,
+ SHA3_384 = 22,
+ SHA3_512 = 23,
};
std::ostream&
diff --git a/tests/unit-tests/security/transform/digest-filter.t.cpp b/tests/unit-tests/security/transform/digest-filter.t.cpp
index 1a509eb..5c0aaca 100644
--- a/tests/unit-tests/security/transform/digest-filter.t.cpp
+++ b/tests/unit-tests/security/transform/digest-filter.t.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2017 Regents of the University of California.
+ * Copyright (c) 2013-2018 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -163,6 +163,55 @@
}
#endif // OPENSSL_VERSION_NUMBER >= 0x1010000fL && !defined(OPENSSL_NO_BLAKE2)
+#if OPENSSL_VERSION_NUMBER >= 0x10101001L
+BOOST_AUTO_TEST_CASE(AlgorithmSha3_224)
+{
+ const uint8_t out[] = {
+ 0x6b, 0x4e, 0x03, 0x42, 0x36, 0x67, 0xdb, 0xb7, 0x3b, 0x6e, 0x15, 0x45, 0x4f, 0x0e, 0xb1, 0xab,
+ 0xd4, 0x59, 0x7f, 0x9a, 0x1b, 0x07, 0x8e, 0x3f, 0x5b, 0x5a, 0x6b, 0xc7,
+ };
+ OBufferStream os;
+ bufferSource("") >> digestFilter(DigestAlgorithm::SHA3_224) >> streamSink(os);
+ BOOST_CHECK_EQUAL_COLLECTIONS(out, out + sizeof(out), os.buf()->begin(), os.buf()->end());
+}
+
+BOOST_AUTO_TEST_CASE(AlgorithmSha3_256)
+{
+ const uint8_t out[] = {
+ 0xa7, 0xff, 0xc6, 0xf8, 0xbf, 0x1e, 0xd7, 0x66, 0x51, 0xc1, 0x47, 0x56, 0xa0, 0x61, 0xd6, 0x62,
+ 0xf5, 0x80, 0xff, 0x4d, 0xe4, 0x3b, 0x49, 0xfa, 0x82, 0xd8, 0x0a, 0x4b, 0x80, 0xf8, 0x43, 0x4a,
+ };
+ OBufferStream os;
+ bufferSource("") >> digestFilter(DigestAlgorithm::SHA3_256) >> streamSink(os);
+ BOOST_CHECK_EQUAL_COLLECTIONS(out, out + sizeof(out), os.buf()->begin(), os.buf()->end());
+}
+
+BOOST_AUTO_TEST_CASE(AlgorithmSha3_384)
+{
+ const uint8_t out[] = {
+ 0x0c, 0x63, 0xa7, 0x5b, 0x84, 0x5e, 0x4f, 0x7d, 0x01, 0x10, 0x7d, 0x85, 0x2e, 0x4c, 0x24, 0x85,
+ 0xc5, 0x1a, 0x50, 0xaa, 0xaa, 0x94, 0xfc, 0x61, 0x99, 0x5e, 0x71, 0xbb, 0xee, 0x98, 0x3a, 0x2a,
+ 0xc3, 0x71, 0x38, 0x31, 0x26, 0x4a, 0xdb, 0x47, 0xfb, 0x6b, 0xd1, 0xe0, 0x58, 0xd5, 0xf0, 0x04,
+ };
+ OBufferStream os;
+ bufferSource("") >> digestFilter(DigestAlgorithm::SHA3_384) >> streamSink(os);
+ BOOST_CHECK_EQUAL_COLLECTIONS(out, out + sizeof(out), os.buf()->begin(), os.buf()->end());
+}
+
+BOOST_AUTO_TEST_CASE(AlgorithmSha3_512)
+{
+ const uint8_t out[] = {
+ 0xa6, 0x9f, 0x73, 0xcc, 0xa2, 0x3a, 0x9a, 0xc5, 0xc8, 0xb5, 0x67, 0xdc, 0x18, 0x5a, 0x75, 0x6e,
+ 0x97, 0xc9, 0x82, 0x16, 0x4f, 0xe2, 0x58, 0x59, 0xe0, 0xd1, 0xdc, 0xc1, 0x47, 0x5c, 0x80, 0xa6,
+ 0x15, 0xb2, 0x12, 0x3a, 0xf1, 0xf5, 0xf9, 0x4c, 0x11, 0xe3, 0xe9, 0x40, 0x2c, 0x3a, 0xc5, 0x58,
+ 0xf5, 0x00, 0x19, 0x9d, 0x95, 0xb6, 0xd3, 0xe3, 0x01, 0x75, 0x85, 0x86, 0x28, 0x1d, 0xcd, 0x26,
+ };
+ OBufferStream os;
+ bufferSource("") >> digestFilter(DigestAlgorithm::SHA3_512) >> streamSink(os);
+ BOOST_CHECK_EQUAL_COLLECTIONS(out, out + sizeof(out), os.buf()->begin(), os.buf()->end());
+}
+#endif // OPENSSL_VERSION_NUMBER >= 0x10101001L
+
BOOST_AUTO_TEST_SUITE_END() // TestDigestFilter
BOOST_AUTO_TEST_SUITE_END() // Transform
BOOST_AUTO_TEST_SUITE_END() // Security