]> git.saurik.com Git - apple/xnu.git/blame_incremental - osfmk/corecrypto/cc/src/cc_clear.c
xnu-3789.1.32.tar.gz
[apple/xnu.git] / osfmk / corecrypto / cc / src / cc_clear.c
... / ...
CommitLineData
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 ) )
16void 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>
22static void cc_clear(size_t len, void *dst)
23{
24 SecureZeroMemory(dst, len);
25}
26#else
27void 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*/