diff options
| author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-07-06 13:00:59 +0200 |
|---|---|---|
| committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-07-06 13:00:59 +0200 |
| commit | d12ecf68276ab0e57ea578d763f23b2143e57ed8 (patch) | |
| tree | 9ddf4b21c9a918e4d97679a259ea6dcd9de742c7 /libtomcrypt/pk/asn1/der/boolean | |
| parent | b6d0f4da862e17344fca35db8d9ed0dce39e757f (diff) | |
| download | cryptodev-linux-d12ecf68276ab0e57ea578d763f23b2143e57ed8.tar.gz cryptodev-linux-d12ecf68276ab0e57ea578d763f23b2143e57ed8.tar.xz cryptodev-linux-d12ecf68276ab0e57ea578d763f23b2143e57ed8.zip | |
Added libtomcrypt
Diffstat (limited to 'libtomcrypt/pk/asn1/der/boolean')
| -rw-r--r-- | libtomcrypt/pk/asn1/der/boolean/der_decode_boolean.c | 47 | ||||
| -rw-r--r-- | libtomcrypt/pk/asn1/der/boolean/der_encode_boolean.c | 51 | ||||
| -rw-r--r-- | libtomcrypt/pk/asn1/der/boolean/der_length_boolean.c | 35 |
3 files changed, 133 insertions, 0 deletions
diff --git a/libtomcrypt/pk/asn1/der/boolean/der_decode_boolean.c b/libtomcrypt/pk/asn1/der/boolean/der_decode_boolean.c new file mode 100644 index 0000000..f374aa6 --- /dev/null +++ b/libtomcrypt/pk/asn1/der/boolean/der_decode_boolean.c @@ -0,0 +1,47 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" + +/** + @file der_decode_boolean.c + ASN.1 DER, decode a BOOLEAN, Tom St Denis +*/ + + +#ifdef LTC_DER + +/** + Read a BOOLEAN + @param in The destination for the DER encoded BOOLEAN + @param inlen The size of the DER BOOLEAN + @param out [out] The boolean to decode + @return CRYPT_OK if successful +*/ +int der_decode_boolean(const unsigned char *in, unsigned long inlen, + int *out) +{ + LTC_ARGCHK(in != NULL); + LTC_ARGCHK(out != NULL); + + if (inlen != 3 || in[0] != 0x01 || in[1] != 0x01 || (in[2] != 0x00 && in[2] != 0xFF)) { + return CRYPT_INVALID_ARG; + } + + *out = (in[2]==0xFF) ? 1 : 0; + + return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_decode_boolean.c,v $ */ +/* $Revision: 1.2 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/libtomcrypt/pk/asn1/der/boolean/der_encode_boolean.c b/libtomcrypt/pk/asn1/der/boolean/der_encode_boolean.c new file mode 100644 index 0000000..df497bf --- /dev/null +++ b/libtomcrypt/pk/asn1/der/boolean/der_encode_boolean.c @@ -0,0 +1,51 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" + +/** + @file der_encode_boolean.c + ASN.1 DER, encode a BOOLEAN, Tom St Denis +*/ + + +#ifdef LTC_DER + +/** + Store a BOOLEAN + @param in The boolean to encode + @param out [out] The destination for the DER encoded BOOLEAN + @param outlen [in/out] The max size and resulting size of the DER BOOLEAN + @return CRYPT_OK if successful +*/ +int der_encode_boolean(int in, + unsigned char *out, unsigned long *outlen) +{ + LTC_ARGCHK(outlen != NULL); + LTC_ARGCHK(out != NULL); + + if (*outlen < 3) { + *outlen = 3; + return CRYPT_BUFFER_OVERFLOW; + } + + *outlen = 3; + out[0] = 0x01; + out[1] = 0x01; + out[2] = in ? 0xFF : 0x00; + + return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_encode_boolean.c,v $ */ +/* $Revision: 1.4 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ diff --git a/libtomcrypt/pk/asn1/der/boolean/der_length_boolean.c b/libtomcrypt/pk/asn1/der/boolean/der_length_boolean.c new file mode 100644 index 0000000..aa3e03d --- /dev/null +++ b/libtomcrypt/pk/asn1/der/boolean/der_length_boolean.c @@ -0,0 +1,35 @@ +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ +#include "tomcrypt.h" + +/** + @file der_length_boolean.c + ASN.1 DER, get length of a BOOLEAN, Tom St Denis +*/ + +#ifdef LTC_DER +/** + Gets length of DER encoding of a BOOLEAN + @param outlen [out] The length of the DER encoding + @return CRYPT_OK if successful +*/ +int der_length_boolean(unsigned long *outlen) +{ + LTC_ARGCHK(outlen != NULL); + *outlen = 3; + return CRYPT_OK; +} + +#endif + +/* $Source: /cvs/libtom/libtomcrypt/src/pk/asn1/der/boolean/der_length_boolean.c,v $ */ +/* $Revision: 1.3 $ */ +/* $Date: 2006/12/28 01:27:24 $ */ |
