| 1 |
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */ |
| 2 |
/* SPDX-License-Identifier: Unlicense */ |
| 3 |
#include "tomcrypt_private.h" |
| 4 |
|
| 5 |
/** |
| 6 |
@file der_encode_boolean.c |
| 7 |
ASN.1 DER, encode a BOOLEAN, Tom St Denis |
| 8 |
*/ |
| 9 |
|
| 10 |
|
| 11 |
#ifdef LTC_DER |
| 12 |
|
| 13 |
/** |
| 14 |
Store a BOOLEAN |
| 15 |
@param in The boolean to encode |
| 16 |
@param out [out] The destination for the DER encoded BOOLEAN |
| 17 |
@param outlen [in/out] The max size and resulting size of the DER BOOLEAN |
| 18 |
@return CRYPT_OK if successful |
| 19 |
*/ |
| 20 |
int der_encode_boolean(int in, |
| 21 |
unsigned char *out, unsigned long *outlen) |
| 22 |
{ |
| 23 |
LTC_ARGCHK(outlen != NULL); |
| 24 |
LTC_ARGCHK(out != NULL); |
| 25 |
|
| 26 |
if (*outlen < 3) { |
| 27 |
*outlen = 3; |
| 28 |
return CRYPT_BUFFER_OVERFLOW; |
| 29 |
} |
| 30 |
|
| 31 |
*outlen = 3; |
| 32 |
out[0] = 0x01; |
| 33 |
out[1] = 0x01; |
| 34 |
out[2] = in ? 0xFF : 0x00; |
| 35 |
|
| 36 |
return CRYPT_OK; |
| 37 |
} |
| 38 |
|
| 39 |
#endif |