1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
12 @file der_length_ia5_string.c
13 ASN.1 DER, get length of IA5 STRING, Tom St Denis
125 int der_ia5_char_encode(int c)
128 for (x = 0; x < (int)(sizeof(ia5_table)/sizeof(ia5_table[0])); x++) {
129 if (ia5_table[x].code == c) {
130 return ia5_table[x].value;
136 int der_ia5_value_decode(int v)
139 for (x = 0; x < (int)(sizeof(ia5_table)/sizeof(ia5_table[0])); x++) {
140 if (ia5_table[x].value == v) {
141 return ia5_table[x].code;
148 Gets length of DER encoding of IA5 STRING
149 @param octets The values you want to encode
150 @param noctets The number of octets in the string to encode
151 @param outlen [out] The length of the DER encoding for the given string
152 @return CRYPT_OK if successful
154 int der_length_ia5_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen)
158 LTC_ARGCHK(outlen != NULL);
159 LTC_ARGCHK(octets != NULL);
161 /* scan string for validity */
162 for (x = 0; x < noctets; x++) {
163 if (der_ia5_char_encode(octets[x]) == -1) {
164 return CRYPT_INVALID_ARG;
169 /* 16 LL DD DD DD ... */
170 *outlen = 2 + noctets;
171 } else if (noctets < 256) {
172 /* 16 81 LL DD DD DD ... */
173 *outlen = 3 + noctets;
174 } else if (noctets < 65536UL) {
175 /* 16 82 LL LL DD DD DD ... */
176 *outlen = 4 + noctets;
177 } else if (noctets < 16777216UL) {
178 /* 16 83 LL LL LL DD DD DD ... */
179 *outlen = 5 + noctets;
181 return CRYPT_INVALID_ARG;
190 /* ref: $Format:%D$ */
191 /* git commit: $Format:%H$ */
192 /* commit time: $Format:%ai$ */