1 // SPDX-License-Identifier: BSD-2-Clause 2 /* LibTomCrypt, modular cryptographic library -- Tom St Denis 3 * 4 * LibTomCrypt is a library that provides various cryptographic 5 * algorithms in a highly modular and flexible manner. 6 * 7 * The library is free for all purposes without any express 8 * guarantee it works. 9 */ 10 #include "tomcrypt_private.h" 11 12 /** 13 @file der_encode_boolean.c 14 ASN.1 DER, encode a BOOLEAN, Tom St Denis 15 */ 16 17 18 #ifdef LTC_DER 19 20 /** 21 Store a BOOLEAN 22 @param in The boolean to encode 23 @param out [out] The destination for the DER encoded BOOLEAN 24 @param outlen [in/out] The max size and resulting size of the DER BOOLEAN 25 @return CRYPT_OK if successful 26 */ der_encode_boolean(int in,unsigned char * out,unsigned long * outlen)27int der_encode_boolean(int in, 28 unsigned char *out, unsigned long *outlen) 29 { 30 LTC_ARGCHK(outlen != NULL); 31 LTC_ARGCHK(out != NULL); 32 33 if (*outlen < 3) { 34 *outlen = 3; 35 return CRYPT_BUFFER_OVERFLOW; 36 } 37 38 *outlen = 3; 39 out[0] = 0x01; 40 out[1] = 0x01; 41 out[2] = in ? 0xFF : 0x00; 42 43 return CRYPT_OK; 44 } 45 46 #endif 47 48 /* ref: $Format:%D$ */ 49 /* git commit: $Format:%H$ */ 50 /* commit time: $Format:%ai$ */ 51