[compiler-rt] r348678 - Add interceptors for the rmd160(3) from NetBSD
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 7 17:47:29 PST 2018
Author: kamil
Date: Fri Dec 7 17:47:29 2018
New Revision: 348678
URL: http://llvm.org/viewvc/llvm-project?rev=348678&view=rev
Log:
Add interceptors for the rmd160(3) from NetBSD
Summary:
RMD160Init, RMD160Update, RMD160Final, RMD160Transform, RMD160End,
RMD160File, RMD160Data - calculates the ``RIPEMD-160'' message digest.
Add a dedicated test for this API.
Reviewers: vitalybuka, joerg
Reviewed By: vitalybuka
Subscribers: kubamracek, llvm-commits, mgorny, #sanitizers
Tags: #sanitizers
Differential Revision: https://reviews.llvm.org/D54991
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/rmd160.cc
Modified:
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=348678&r1=348677&r2=348678&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Fri Dec 7 17:47:29 2018
@@ -8058,6 +8058,99 @@ INTERCEPTOR(char *, MD4Data, const unsig
#define INIT_MD4
#endif
+#if SANITIZER_INTERCEPT_RMD160
+INTERCEPTOR(void, RMD160Init, void *context) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160Init, context);
+ REAL(RMD160Init)(context);
+ if (context)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, RMD160_CTX_sz);
+}
+INTERCEPTOR(void, RMD160Update, void *context, const u8 *data, unsigned len) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160Update, context, data, len);
+ if (data && len > 0)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, data, len);
+ if (context)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, context, RMD160_CTX_sz);
+ REAL(RMD160Update)(context, data, len);
+ if (context)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, context, RMD160_CTX_sz);
+}
+INTERCEPTOR(void, RMD160Final, u8 digest[20], void *context) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160Final, digest, context);
+ if (context)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, context, RMD160_CTX_sz);
+ REAL(RMD160Final)(digest, context);
+ if (digest)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, digest, sizeof(u8) * 20);
+}
+INTERCEPTOR(void, RMD160Transform, u32 state[5], u16 buffer[16]) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160Transform, state, buffer);
+ if (state)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, state, sizeof(u32) * 5);
+ if (buffer)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, buffer, sizeof(u32) * 16);
+ REAL(RMD160Transform)(state, buffer);
+ if (state)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, state, sizeof(u32) * 5);
+}
+INTERCEPTOR(char *, RMD160End, void *context, char *buf) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160End, context, buf);
+ if (context)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, context, RMD160_CTX_sz);
+ char *ret = REAL(RMD160End)(context, buf);
+ if (ret)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ret, RMD160_return_length);
+ return ret;
+}
+INTERCEPTOR(char *, RMD160File, char *filename, char *buf) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160File, filename, buf);
+ if (filename)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, filename, REAL(strlen)(filename) + 1);
+ char *ret = REAL(RMD160File)(filename, buf);
+ if (ret)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ret, RMD160_return_length);
+ return ret;
+}
+INTERCEPTOR(char *, RMD160FileChunk, char *filename, char *buf, OFF_T offset,
+ OFF_T length) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160FileChunk, filename, buf, offset, length);
+ if (filename)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, filename, REAL(strlen)(filename) + 1);
+ char *ret = REAL(RMD160FileChunk)(filename, buf, offset, length);
+ if (ret)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ret, RMD160_return_length);
+ return ret;
+}
+INTERCEPTOR(char *, RMD160Data, u8 *data, SIZE_T len, char *buf) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, RMD160Data, data, len, buf);
+ if (data && len > 0)
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, data, len);
+ char *ret = REAL(RMD160Data)(data, len, buf);
+ if (ret)
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ret, RMD160_return_length);
+ return ret;
+}
+#define INIT_RMD160 \
+ COMMON_INTERCEPT_FUNCTION(RMD160Init); \
+ COMMON_INTERCEPT_FUNCTION(RMD160Update); \
+ COMMON_INTERCEPT_FUNCTION(RMD160Final); \
+ COMMON_INTERCEPT_FUNCTION(RMD160Transform); \
+ COMMON_INTERCEPT_FUNCTION(RMD160End); \
+ COMMON_INTERCEPT_FUNCTION(RMD160File); \
+ COMMON_INTERCEPT_FUNCTION(RMD160FileChunk); \
+ COMMON_INTERCEPT_FUNCTION(RMD160Data)
+#else
+#define INIT_RMD160
+#endif
+
static void InitializeCommonInterceptors() {
static u64 metadata_mem[sizeof(MetadataHashMap) / sizeof(u64) + 1];
interceptor_metadata_map =
@@ -8330,6 +8423,7 @@ static void InitializeCommonInterceptors
INIT_CAPSICUM;
INIT_SHA1;
INIT_MD4;
+ INIT_RMD160;
INIT___PRINTF_CHK;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=348678&r1=348677&r2=348678&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Dec 7 17:47:29 2018
@@ -537,5 +537,6 @@
#define SANITIZER_INTERCEPT_CAPSICUM SI_FREEBSD
#define SANITIZER_INTERCEPT_SHA1 SI_NETBSD
#define SANITIZER_INTERCEPT_MD4 SI_NETBSD
+#define SANITIZER_INTERCEPT_RMD160 SI_NETBSD
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc?rev=348678&r1=348677&r2=348678&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc Fri Dec 7 17:47:29 2018
@@ -2107,6 +2107,9 @@ const unsigned SHA1_return_length = SHA1
const unsigned MD4_CTX_sz = sizeof(MD4_CTX);
const unsigned MD4_return_length = MD4_DIGEST_STRING_LENGTH;
+
+const unsigned RMD160_CTX_sz = sizeof(RMD160_CTX);
+const unsigned RMD160_return_length = RMD160_DIGEST_STRING_LENGTH;
} // namespace __sanitizer
using namespace __sanitizer;
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h?rev=348678&r1=348677&r2=348678&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_netbsd.h Fri Dec 7 17:47:29 2018
@@ -2231,6 +2231,9 @@ extern const unsigned SHA1_return_length
extern const unsigned MD4_CTX_sz;
extern const unsigned MD4_return_length;
+
+extern const unsigned RMD160_CTX_sz;
+extern const unsigned RMD160_return_length;
} // namespace __sanitizer
#define CHECK_TYPE_SIZE(TYPE) \
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/rmd160.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/rmd160.cc?rev=348678&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/rmd160.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/NetBSD/rmd160.cc Fri Dec 7 17:47:29 2018
@@ -0,0 +1,133 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <rmd160.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1() {
+ RMD160_CTX ctx;
+ uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
+ uint8_t digest[RMD160_DIGEST_LENGTH];
+
+ RMD160Init(&ctx);
+ RMD160Update(&ctx, entropy, __arraycount(entropy));
+ RMD160Final(digest, &ctx);
+
+ printf("test1: '");
+ for (size_t i = 0; i < __arraycount(digest); i++)
+ printf("%02x", digest[i]);
+ printf("'\n");
+}
+
+void test2() {
+ RMD160_CTX ctx;
+ uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
+ char digest[RMD160_DIGEST_STRING_LENGTH];
+
+ RMD160Init(&ctx);
+ RMD160Update(&ctx, entropy, __arraycount(entropy));
+ char *p = RMD160End(&ctx, digest);
+ assert(p == digest);
+
+ printf("test2: '%s'\n", digest);
+}
+
+void test3() {
+ RMD160_CTX ctx;
+ uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
+
+ RMD160Init(&ctx);
+ RMD160Update(&ctx, entropy, __arraycount(entropy));
+ char *p = RMD160End(&ctx, NULL);
+ assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
+
+ printf("test3: '%s'\n", p);
+
+ free(p);
+}
+
+void test4() {
+ char digest[RMD160_DIGEST_STRING_LENGTH];
+
+ char *p = RMD160File("/etc/fstab", digest);
+ assert(p == digest);
+
+ printf("test4: '%s'\n", p);
+}
+
+void test5() {
+ char *p = RMD160File("/etc/fstab", NULL);
+ assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
+
+ printf("test5: '%s'\n", p);
+
+ free(p);
+}
+
+void test6() {
+ char digest[RMD160_DIGEST_STRING_LENGTH];
+
+ char *p = RMD160FileChunk("/etc/fstab", digest, 10, 20);
+ assert(p == digest);
+
+ printf("test6: '%s'\n", p);
+}
+
+void test7() {
+ char *p = RMD160FileChunk("/etc/fstab", NULL, 10, 20);
+ assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
+
+ printf("test7: '%s'\n", p);
+
+ free(p);
+}
+
+void test8() {
+ uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
+ char digest[RMD160_DIGEST_STRING_LENGTH];
+
+ char *p = RMD160Data(entropy, __arraycount(entropy), digest);
+ assert(p == digest);
+
+ printf("test8: '%s'\n", p);
+}
+
+void test9() {
+ uint8_t entropy[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66 };
+
+ char *p = RMD160Data(entropy, __arraycount(entropy), NULL);
+ assert(strlen(p) == RMD160_DIGEST_STRING_LENGTH - 1);
+
+ printf("test9: '%s'\n", p);
+
+ free(p);
+}
+
+int main(void) {
+ printf("RMD160\n");
+
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+ test6();
+ test7();
+ test8();
+ test9();
+
+ // CHECK: RMD160
+ // CHECK: test1: '2787e5a006365df6e8e799315b669dc34866783c'
+ // CHECK: test2: '2787e5a006365df6e8e799315b669dc34866783c'
+ // CHECK: test3: '2787e5a006365df6e8e799315b669dc34866783c'
+ // CHECK: test4: '{{.*}}'
+ // CHECK: test5: '{{.*}}'
+ // CHECK: test6: '{{.*}}'
+ // CHECK: test7: '{{.*}}'
+ // CHECK: test8: '2787e5a006365df6e8e799315b669dc34866783c'
+ // CHECK: test9: '2787e5a006365df6e8e799315b669dc34866783c'
+
+ return 0;
+}
More information about the llvm-commits
mailing list