]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * cc_clear.c | |
3 | * corecrypto | |
4 | * | |
5 | * Created on 05/21/2014 | |
6 | * | |
7 | * Copyright (c) 2014,2015 Apple Inc. All rights reserved. | |
8 | * | |
9 | */ | |
10 | ||
11 | #include <corecrypto/cc.h> | |
12 | ||
13 | //rdar://problem/26986552 | |
14 | ||
15 | #if ( CC_HAS_MEMSET_S == 1 ) && (defined( __STDC_WANT_LIB_EXT1__ ) && ( __STDC_WANT_LIB_EXT1__ == 1 ) ) | |
16 | void cc_clear(size_t len, void *dst) | |
17 | { | |
18 | memset_s(dst,len,0,len); | |
19 | } | |
20 | #elif defined(_WIN32) && !defined(__clang__) //Clang with Microsoft CodeGen, doesn't support SecureZeroMemory | |
21 | #include <windows.h> | |
22 | static void cc_clear(size_t len, void *dst) | |
23 | { | |
24 | SecureZeroMemory(dst, len); | |
25 | } | |
26 | #else | |
27 | void cc_clear(size_t len, void *dst) | |
28 | { | |
29 | volatile char *vptr = (volatile char *)dst; | |
30 | while (len--) | |
31 | *vptr++ = '\0'; | |
32 | } | |
33 | #endif | |
34 | ||
35 | /* This is an altarnative for clang that should work | |
36 | void cc_clear(size_t len, void *dst) __attribute__ ((optnone)) | |
37 | { | |
38 | cc_zero(len,dst); | |
39 | } | |
40 | */ |