Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -7348,6 +7348,97 @@ #define INIT_SETVBUF #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); +} +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 = new((void *)&metadata_mem) MetadataHashMap(); @@ -7604,6 +7695,7 @@ INIT_GETMNTINFO; INIT_MI_VECTOR_HASH; INIT_SETVBUF; + INIT_RMD160; INIT___PRINTF_CHK; } Index: lib/sanitizer_common/sanitizer_platform_interceptors.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_interceptors.h +++ lib/sanitizer_common/sanitizer_platform_interceptors.h @@ -520,5 +520,6 @@ SI_LINUX || SI_MAC) #define SANITIZER_INTERCEPT_GETMNTINFO SI_NETBSD #define SANITIZER_INTERCEPT_MI_VECTOR_HASH SI_NETBSD +#define SANITIZER_INTERCEPT_RMD160 SI_NETBSD #endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.h =================================================================== --- lib/sanitizer_common/sanitizer_platform_limits_netbsd.h +++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.h @@ -2202,6 +2202,9 @@ extern const int si_SEGV_MAPERR; extern const int si_SEGV_ACCERR; + +extern const unsigned RMD160_CTX_sz; +extern const unsigned RMD160_return_length; } // namespace __sanitizer #define CHECK_TYPE_SIZE(TYPE) \ Index: lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc =================================================================== --- lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc +++ lib/sanitizer_common/sanitizer_platform_limits_netbsd.cc @@ -2092,6 +2092,9 @@ const int si_SEGV_MAPERR = SEGV_MAPERR; const int si_SEGV_ACCERR = SEGV_ACCERR; + +const unsigned RMD160_CTX_sz = sizeof(RMD160_CTX); +const unsigned RMD160_return_length = RMD160_DIGEST_STRING_LENGTH; } // namespace __sanitizer using namespace __sanitizer; Index: test/sanitizer_common/TestCases/NetBSD/rmd160.cc =================================================================== --- /dev/null +++ test/sanitizer_common/TestCases/NetBSD/rmd160.cc @@ -0,0 +1,133 @@ +// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s + +#include +#include +#include +#include +#include + +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; +}