Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move all Keccack functions into our own C++ namespace to avoid symbol…

… collissions.
  • Loading branch information...
commit 418a76c7861841c2a74273c6b7997b8457b9b35b 1 parent 9d39ea1
@FooBarWidget FooBarWidget authored
View
8 binding.gyp
@@ -4,10 +4,10 @@
"target_name": "sha3",
"sources": [
"src/addon.cpp",
- "src/displayIntermediateValues.c",
- "src/KeccakF-1600-reference.c",
- "src/KeccakNISTInterface.c",
- "src/KeccakSponge.c"
+ "src/displayIntermediateValues.cpp",
+ "src/KeccakF-1600-reference.cpp",
+ "src/KeccakNISTInterface.cpp",
+ "src/KeccakSponge.cpp"
]
}
]
View
4 src/KeccakF-1600-interface.h
@@ -16,6 +16,8 @@ and related or neighboring rights to the source code in this file.
#include "KeccakF-1600-int-set.h"
+namespace Node_SHA3 {
+
void KeccakInitialize( void );
void KeccakInitializeState(unsigned char *state);
void KeccakPermutation(unsigned char *state);
@@ -43,4 +45,6 @@ void KeccakExtract1024bits(const unsigned char *state, unsigned char *data);
#endif
void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int laneCount);
+} // namespace
+
#endif
View
4 src/KeccakF-1600-reference.c → src/KeccakF-1600-reference.cpp
@@ -18,6 +18,8 @@ and related or neighboring rights to the source code in this file.
#include "KeccakNISTInterface.h"
#include "KeccakF-1600-interface.h"
+namespace Node_SHA3 {
+
typedef unsigned char UINT8;
typedef unsigned long long int UINT64;
@@ -298,3 +300,5 @@ void KeccakExtract(const unsigned char *state, unsigned char *data, unsigned int
{
memcpy(data, state, laneCount*8);
}
+
+} // namespace
View
11 src/KeccakNISTInterface.c → src/KeccakNISTInterface.cpp
@@ -15,6 +15,8 @@ and related or neighboring rights to the source code in this file.
#include "KeccakNISTInterface.h"
#include "KeccakF-1600-interface.h"
+namespace Node_SHA3 {
+
HashReturn Init(hashState *state, int hashbitlen)
{
switch(hashbitlen) {
@@ -43,14 +45,14 @@ HashReturn Init(hashState *state, int hashbitlen)
HashReturn Update(hashState *state, const BitSequence *data, DataLength databitlen)
{
if ((databitlen % 8) == 0)
- return Absorb((spongeState*)state, data, databitlen);
+ return (HashReturn) Absorb((spongeState*)state, data, databitlen);
else {
- HashReturn ret = Absorb((spongeState*)state, data, databitlen - (databitlen % 8));
+ HashReturn ret = (HashReturn) Absorb((spongeState*)state, data, databitlen - (databitlen % 8));
if (ret == SUCCESS) {
unsigned char lastByte;
// Align the last partial byte to the least significant bits
lastByte = data[databitlen/8] >> (8 - (databitlen % 8));
- return Absorb((spongeState*)state, &lastByte, databitlen % 8);
+ return (HashReturn) Absorb((spongeState*)state, &lastByte, databitlen % 8);
}
else
return ret;
@@ -59,7 +61,7 @@ HashReturn Update(hashState *state, const BitSequence *data, DataLength databitl
HashReturn Final(hashState *state, BitSequence *hashval)
{
- return Squeeze(state, hashval, state->fixedOutputLength);
+ return (HashReturn) Squeeze(state, hashval, state->fixedOutputLength);
}
HashReturn Hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval)
@@ -79,3 +81,4 @@ HashReturn Hash(int hashbitlen, const BitSequence *data, DataLength databitlen,
return result;
}
+} // namespace
View
4 src/KeccakNISTInterface.h
@@ -16,6 +16,8 @@ and related or neighboring rights to the source code in this file.
#include "KeccakSponge.h"
+namespace Node_SHA3 {
+
typedef unsigned char BitSequence;
typedef unsigned long long DataLength;
typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn;
@@ -67,4 +69,6 @@ HashReturn Final(hashState *state, BitSequence *hashval);
*/
HashReturn Hash(int hashbitlen, const BitSequence *data, DataLength databitlen, BitSequence *hashval);
+} // namespace
+
#endif
View
4 src/KeccakSponge.c → src/KeccakSponge.cpp
@@ -18,6 +18,8 @@ and related or neighboring rights to the source code in this file.
#include "displayIntermediateValues.h"
#endif
+namespace Node_SHA3 {
+
int InitSponge(spongeState *state, unsigned int rate, unsigned int capacity)
{
if (rate+capacity != 1600)
@@ -264,3 +266,5 @@ int Squeeze(spongeState *state, unsigned char *output, unsigned long long output
}
return 0;
}
+
+} // namespace
View
4 src/KeccakSponge.h
@@ -27,6 +27,8 @@ and related or neighboring rights to the source code in this file.
#define ALIGN
#endif
+namespace Node_SHA3 {
+
ALIGN typedef struct spongeStateStruct {
ALIGN unsigned char state[KeccakPermutationSizeInBytes];
ALIGN unsigned char dataQueue[KeccakMaximumRateInBytes];
@@ -73,4 +75,6 @@ int Absorb(spongeState *state, const unsigned char *data, unsigned long long dat
*/
int Squeeze(spongeState *state, unsigned char *output, unsigned long long outputLength);
+} // namespace
+
#endif
View
5 src/addon.cpp
@@ -5,9 +5,7 @@
#include <cassert>
#include <cstring>
-extern "C" {
- #include "KeccakNISTInterface.h"
-}
+#include "KeccakNISTInterface.h"
#define MAX_DIGEST_SIZE 64
#define ASSERT_IS_STRING_OR_BUFFER(val) \
@@ -17,6 +15,7 @@ extern "C" {
using namespace node;
using namespace v8;
+using namespace Node_SHA3;
static void toHex(const char *data_buf, size_t size, char *output);
View
4 src/displayIntermediateValues.c → src/displayIntermediateValues.cpp
@@ -15,6 +15,8 @@ and related or neighboring rights to the source code in this file.
#include "displayIntermediateValues.h"
#include "KeccakNISTInterface.h"
+namespace Node_SHA3 {
+
FILE *intermediateValueFile = 0;
int displayLevel = 0;
@@ -115,3 +117,5 @@ void displayText(int level, const char *text)
fprintf(intermediateValueFile, "\n");
}
}
+
+} // namespace
View
4 src/displayIntermediateValues.h
@@ -16,6 +16,8 @@ and related or neighboring rights to the source code in this file.
#include <stdio.h>
+namespace Node_SHA3 {
+
void displaySetIntermediateValueFile(FILE *f);
void displaySetLevel(int level);
void displayBytes(int level, const char *text, const unsigned char *bytes, unsigned int size);
@@ -26,4 +28,6 @@ void displayStateAs64bitWords(int level, const char *text, const unsigned long l
void displayRoundNumber(int level, unsigned int i);
void displayText(int level, const char *text);
+} // namespace
+
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.