Lines Matching refs:p
31 int mbedtls_asn1_write_len(unsigned char **p, const unsigned char *start, size_t len) in mbedtls_asn1_write_len() argument
34 if (*p - start < 1) { in mbedtls_asn1_write_len()
38 *--(*p) = (unsigned char) len; in mbedtls_asn1_write_len()
43 if (*p - start < 2) { in mbedtls_asn1_write_len()
47 *--(*p) = (unsigned char) len; in mbedtls_asn1_write_len()
48 *--(*p) = 0x81; in mbedtls_asn1_write_len()
53 if (*p - start < 3) { in mbedtls_asn1_write_len()
57 *--(*p) = MBEDTLS_BYTE_0(len); in mbedtls_asn1_write_len()
58 *--(*p) = MBEDTLS_BYTE_1(len); in mbedtls_asn1_write_len()
59 *--(*p) = 0x82; in mbedtls_asn1_write_len()
64 if (*p - start < 4) { in mbedtls_asn1_write_len()
68 *--(*p) = MBEDTLS_BYTE_0(len); in mbedtls_asn1_write_len()
69 *--(*p) = MBEDTLS_BYTE_1(len); in mbedtls_asn1_write_len()
70 *--(*p) = MBEDTLS_BYTE_2(len); in mbedtls_asn1_write_len()
71 *--(*p) = 0x83; in mbedtls_asn1_write_len()
80 if (*p - start < 5) { in mbedtls_asn1_write_len()
84 *--(*p) = MBEDTLS_BYTE_0(len); in mbedtls_asn1_write_len()
85 *--(*p) = MBEDTLS_BYTE_1(len); in mbedtls_asn1_write_len()
86 *--(*p) = MBEDTLS_BYTE_2(len); in mbedtls_asn1_write_len()
87 *--(*p) = MBEDTLS_BYTE_3(len); in mbedtls_asn1_write_len()
88 *--(*p) = 0x84; in mbedtls_asn1_write_len()
95 int mbedtls_asn1_write_tag(unsigned char **p, const unsigned char *start, unsigned char tag) in mbedtls_asn1_write_tag() argument
97 if (*p - start < 1) { in mbedtls_asn1_write_tag()
101 *--(*p) = tag; in mbedtls_asn1_write_tag()
106 int mbedtls_asn1_write_raw_buffer(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_raw_buffer() argument
111 if (*p < start || (size_t) (*p - start) < size) { in mbedtls_asn1_write_raw_buffer()
116 (*p) -= len; in mbedtls_asn1_write_raw_buffer()
117 memcpy(*p, buf, len); in mbedtls_asn1_write_raw_buffer()
123 int mbedtls_asn1_write_mpi(unsigned char **p, const unsigned char *start, const mbedtls_mpi *X) in mbedtls_asn1_write_mpi() argument
138 if (*p < start || (size_t) (*p - start) < len) { in mbedtls_asn1_write_mpi()
142 (*p) -= len; in mbedtls_asn1_write_mpi()
143 MBEDTLS_MPI_CHK(mbedtls_mpi_write_binary(X, *p, len)); in mbedtls_asn1_write_mpi()
148 if (X->s == 1 && **p & 0x80) { in mbedtls_asn1_write_mpi()
149 if (*p - start < 1) { in mbedtls_asn1_write_mpi()
153 *--(*p) = 0x00; in mbedtls_asn1_write_mpi()
157 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in mbedtls_asn1_write_mpi()
158 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_INTEGER)); in mbedtls_asn1_write_mpi()
167 int mbedtls_asn1_write_null(unsigned char **p, const unsigned char *start) in mbedtls_asn1_write_null() argument
174 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, 0)); in mbedtls_asn1_write_null()
175 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_NULL)); in mbedtls_asn1_write_null()
180 int mbedtls_asn1_write_oid(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_oid() argument
186 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, in mbedtls_asn1_write_oid()
188 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in mbedtls_asn1_write_oid()
189 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_OID)); in mbedtls_asn1_write_oid()
194 int mbedtls_asn1_write_algorithm_identifier(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_algorithm_identifier() argument
202 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_null(p, start)); in mbedtls_asn1_write_algorithm_identifier()
207 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_oid(p, start, oid, oid_len)); in mbedtls_asn1_write_algorithm_identifier()
209 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in mbedtls_asn1_write_algorithm_identifier()
210 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, in mbedtls_asn1_write_algorithm_identifier()
217 int mbedtls_asn1_write_bool(unsigned char **p, const unsigned char *start, int boolean) in mbedtls_asn1_write_bool() argument
222 if (*p - start < 1) { in mbedtls_asn1_write_bool()
226 *--(*p) = (boolean) ? 255 : 0; in mbedtls_asn1_write_bool()
229 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in mbedtls_asn1_write_bool()
230 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_BOOLEAN)); in mbedtls_asn1_write_bool()
235 static int asn1_write_tagged_int(unsigned char **p, const unsigned char *start, int val, int tag) in asn1_write_tagged_int() argument
241 if (*p - start < 1) { in asn1_write_tagged_int()
245 *--(*p) = val & 0xff; in asn1_write_tagged_int()
249 if (**p & 0x80) { in asn1_write_tagged_int()
250 if (*p - start < 1) { in asn1_write_tagged_int()
253 *--(*p) = 0x00; in asn1_write_tagged_int()
257 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in asn1_write_tagged_int()
258 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, tag)); in asn1_write_tagged_int()
263 int mbedtls_asn1_write_int(unsigned char **p, const unsigned char *start, int val) in mbedtls_asn1_write_int() argument
265 return asn1_write_tagged_int(p, start, val, MBEDTLS_ASN1_INTEGER); in mbedtls_asn1_write_int()
268 int mbedtls_asn1_write_enum(unsigned char **p, const unsigned char *start, int val) in mbedtls_asn1_write_enum() argument
270 return asn1_write_tagged_int(p, start, val, MBEDTLS_ASN1_ENUMERATED); in mbedtls_asn1_write_enum()
273 int mbedtls_asn1_write_tagged_string(unsigned char **p, const unsigned char *start, int tag, in mbedtls_asn1_write_tagged_string() argument
279 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, in mbedtls_asn1_write_tagged_string()
283 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in mbedtls_asn1_write_tagged_string()
284 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, tag)); in mbedtls_asn1_write_tagged_string()
289 int mbedtls_asn1_write_utf8_string(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_utf8_string() argument
292 return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_UTF8_STRING, text, text_len); in mbedtls_asn1_write_utf8_string()
295 int mbedtls_asn1_write_printable_string(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_printable_string() argument
298 return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_PRINTABLE_STRING, text, in mbedtls_asn1_write_printable_string()
302 int mbedtls_asn1_write_ia5_string(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_ia5_string() argument
305 return mbedtls_asn1_write_tagged_string(p, start, MBEDTLS_ASN1_IA5_STRING, text, text_len); in mbedtls_asn1_write_ia5_string()
308 int mbedtls_asn1_write_named_bitstring(unsigned char **p, in mbedtls_asn1_write_named_bitstring() argument
349 return mbedtls_asn1_write_bitstring(p, start, buf, bits); in mbedtls_asn1_write_named_bitstring()
352 int mbedtls_asn1_write_bitstring(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_bitstring() argument
362 if (*p < start || (size_t) (*p - start) < byte_len + 1) { in mbedtls_asn1_write_bitstring()
371 *--(*p) = buf[byte_len] & ~((0x1 << unused_bits) - 1); in mbedtls_asn1_write_bitstring()
372 (*p) -= byte_len; in mbedtls_asn1_write_bitstring()
373 memcpy(*p, buf, byte_len); in mbedtls_asn1_write_bitstring()
377 *--(*p) = (unsigned char) unused_bits; in mbedtls_asn1_write_bitstring()
379 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in mbedtls_asn1_write_bitstring()
380 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_BIT_STRING)); in mbedtls_asn1_write_bitstring()
385 int mbedtls_asn1_write_octet_string(unsigned char **p, const unsigned char *start, in mbedtls_asn1_write_octet_string() argument
391 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_raw_buffer(p, start, buf, size)); in mbedtls_asn1_write_octet_string()
393 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_len(p, start, len)); in mbedtls_asn1_write_octet_string()
394 MBEDTLS_ASN1_CHK_ADD(len, mbedtls_asn1_write_tag(p, start, MBEDTLS_ASN1_OCTET_STRING)); in mbedtls_asn1_write_octet_string()
408 memcmp(list->oid.p, oid, len) == 0) { in asn1_find_named_data()
436 cur->oid.p = mbedtls_calloc(1, oid_len); in mbedtls_asn1_store_named_data()
437 if (cur->oid.p == NULL) { in mbedtls_asn1_store_named_data()
442 memcpy(cur->oid.p, oid, oid_len); in mbedtls_asn1_store_named_data()
446 cur->val.p = mbedtls_calloc(1, val_len); in mbedtls_asn1_store_named_data()
447 if (cur->val.p == NULL) { in mbedtls_asn1_store_named_data()
448 mbedtls_free(cur->oid.p); in mbedtls_asn1_store_named_data()
457 mbedtls_free(cur->val.p); in mbedtls_asn1_store_named_data()
458 cur->val.p = NULL; in mbedtls_asn1_store_named_data()
465 void *p = mbedtls_calloc(1, val_len); in mbedtls_asn1_store_named_data() local
466 if (p == NULL) { in mbedtls_asn1_store_named_data()
470 mbedtls_free(cur->val.p); in mbedtls_asn1_store_named_data()
471 cur->val.p = p; in mbedtls_asn1_store_named_data()
476 memcpy(cur->val.p, val, val_len); in mbedtls_asn1_store_named_data()