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_teletex_string.c
13 ASN.1 DER, get length of teletex STRING
141 int der_teletex_char_encode(int c)
144 for (x = 0; x < (int)(sizeof(teletex_table)/sizeof(teletex_table[0])); x++) {
145 if (teletex_table[x].code == c) {
146 return teletex_table[x].value;
152 int der_teletex_value_decode(int v)
155 for (x = 0; x < (int)(sizeof(teletex_table)/sizeof(teletex_table[0])); x++) {
156 if (teletex_table[x].value == v) {
157 return teletex_table[x].code;
164 Gets length of DER encoding of teletex STRING
165 @param octets The values you want to encode
166 @param noctets The number of octets in the string to encode
167 @param outlen [out] The length of the DER encoding for the given string
168 @return CRYPT_OK if successful
170 int der_length_teletex_string(const unsigned char *octets, unsigned long noctets, unsigned long *outlen)
174 LTC_ARGCHK(outlen != NULL);
175 LTC_ARGCHK(octets != NULL);
177 /* scan string for validity */
178 for (x = 0; x < noctets; x++) {
179 if (der_teletex_char_encode(octets[x]) == -1) {
180 return CRYPT_INVALID_ARG;
185 /* 16 LL DD DD DD ... */
186 *outlen = 2 + noctets;
187 } else if (noctets < 256) {
188 /* 16 81 LL DD DD DD ... */
189 *outlen = 3 + noctets;
190 } else if (noctets < 65536UL) {
191 /* 16 82 LL LL DD DD DD ... */
192 *outlen = 4 + noctets;
193 } else if (noctets < 16777216UL) {
194 /* 16 83 LL LL LL DD DD DD ... */
195 *outlen = 5 + noctets;
197 return CRYPT_INVALID_ARG;
206 /* ref: $Format:%D$ */
207 /* git commit: $Format:%H$ */
208 /* commit time: $Format:%ai$ */