]> git.saurik.com Git - apple/xnu.git/blame - osfmk/corecrypto/cc/src/cc_clear.c
xnu-3789.1.32.tar.gz
[apple/xnu.git] / osfmk / corecrypto / cc / src / cc_clear.c
CommitLineData
3e170ce0
A
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
39037602
A
13//rdar://problem/26986552
14
15#if ( CC_HAS_MEMSET_S == 1 ) && (defined( __STDC_WANT_LIB_EXT1__ ) && ( __STDC_WANT_LIB_EXT1__ == 1 ) )
3e170ce0
A
16void cc_clear(size_t len, void *dst)
17{
3e170ce0 18 memset_s(dst,len,0,len);
39037602
A
19}
20#elif defined(_WIN32) && !defined(__clang__) //Clang with Microsoft CodeGen, doesn't support SecureZeroMemory
21#include <windows.h>
22static void cc_clear(size_t len, void *dst)
23{
24 SecureZeroMemory(dst, len);
25}
3e170ce0 26#else
39037602
A
27void cc_clear(size_t len, void *dst)
28{
29 volatile char *vptr = (volatile char *)dst;
30 while (len--)
31 *vptr++ = '\0';
3e170ce0 32}
39037602 33#endif
3e170ce0 34
39037602
A
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*/