1 // Copyright 2020 Brian Smith. 2 // 3 // Permission to use, copy, modify, and/or distribute this software for any 4 // purpose with or without fee is hereby granted, provided that the above 5 // copyright notice and this permission notice appear in all copies. 6 // 7 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES 8 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 10 // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 15 #ifndef RING_CHECK_H 16 #define RING_CHECK_H 17 18 // |debug_assert_nonsecret| is like |assert| and should be used (only) when the 19 // assertion does not have any potential to leak a secret. |NDEBUG| controls this 20 // exactly like |assert|. It is emulated when there is no assert.h to make 21 // cross-building easier. 22 // 23 // When reviewing uses of |debug_assert_nonsecret|, verify that the check 24 // really does not have potential to leak a secret. 25 26 #if !defined(GFp_NOSTDLIBINC) 27 # include <assert.h> 28 # define debug_assert_nonsecret(x) assert(x) 29 #else 30 # if !defined(NDEBUG) 31 # define debug_assert_nonsecret(x) ((x) ? ((void)0) : __builtin_trap()) 32 # else 33 # define debug_assert_nonsecret(x) ((void)0) 34 # endif 35 #endif 36 37 // |dev_assert_secret| is like |assert| and should be used (only) when the 38 // assertion operates on secret data in a way that has the potential to leak 39 // the secret. |dev_assert_secret| can only be enabled by changing the |#if 0| 40 // here to |#if 1| (or equivalent) when |NDEBUG| is not defined. This is not 41 // controlled only through |NDEBUG| so that such checks do not leak into debug 42 // builds that may make it into production use. 43 // 44 // When reviewing uses of |dev_assert_secret|, verify that the check really 45 // does have the potential to leak a secret. 46 #if 0 // DO NOT COMMIT CHANGES TO THIS LINE. 47 # define dev_assert_secret debug_assert_nonsecret 48 #else 49 # define dev_assert_secret(x) ((void)0) 50 #endif 51 52 #endif // RING_CHECK_H 53