Add ifdef around SHA_DIGEST_SIZE; remove always_memset.
SHA_DIGEST_SIZE is also defined by the TPM2 library,
so add ifdef guards around its declaration.
Remove always_memset, as global data
initialization may not be portable.
Change-Id: I7c78e7c79d2b778508f813e046e062be24837fdb
Signed-off-by: nagendra modadugu <ngm@google.com>
Reviewed-on: https://chromium-review.googlesource.com/346240
Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Vadim Bendebury <vbendeb@google.com>
diff --git a/Makefile b/Makefile
index 98af7e6..27f63ec 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,6 @@
SOURCES += p256_prng.c
SOURCES += sha.c
SOURCES += sha256.c
-SOURCES += util.c
# Use V=1 for verbose output
ifeq ($(V),)
diff --git a/hmac.c b/hmac.c
index ef6ad82..f920c59 100644
--- a/hmac.c
+++ b/hmac.c
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "cryptoc/hmac.h"
-#include "cryptoc/util.h"
#include <string.h>
#include "cryptoc/sha.h"
@@ -66,6 +65,6 @@
HASH_init(&ctx->hash);
HASH_update(&ctx->hash, ctx->opad, sizeof(ctx->opad));
HASH_update(&ctx->hash, digest, HASH_size(&ctx->hash));
- always_memset(&ctx->opad[0], 0, sizeof(ctx->opad)); // wipe key
+ memset(&ctx->opad[0], 0, sizeof(ctx->opad)); // wipe key
return HASH_final(&ctx->hash);
}
diff --git a/include/cryptoc/sha.h b/include/cryptoc/sha.h
index d490f49..c152ee4 100644
--- a/include/cryptoc/sha.h
+++ b/include/cryptoc/sha.h
@@ -31,7 +31,9 @@
// NOTE: *digest needs to hold SHA_DIGEST_SIZE bytes.
const uint8_t* SHA_hash(const void* data, unsigned int len, uint8_t* digest);
+#ifndef SHA_DIGEST_SIZE
#define SHA_DIGEST_SIZE 20
+#endif
#ifdef __cplusplus
}
diff --git a/include/cryptoc/util.h b/include/cryptoc/util.h
deleted file mode 100644
index 76a3340..0000000
--- a/include/cryptoc/util.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright 2016 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#ifndef SECURITY_UTIL_LITE_UTIL_H_
-#define SECURITY_UTIL_LITE_UTIL_H_
-
-#include <stddef.h>
-
-extern void *(* const volatile always_memset)(void *s, int c, size_t n);
-
-#endif // SECURITY_UTIL_LITE_UTIL_H_
diff --git a/util.c b/util.c
deleted file mode 100644
index 29288e7..0000000
--- a/util.c
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2016 Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-#include "cryptoc/util.h"
-
-#include <string.h>
-
-void *(* const volatile always_memset)(void *s, int c, size_t n) = &memset;