]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/crypto/asn1utils.c
f48c2e12f0acd9d5dde328cf63f8c003d3fdec29
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2018 Merlok
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
9 //-----------------------------------------------------------------------------
11 #include "asn1utils.h"
14 #include <mbedtls/asn1.h>
19 #include "ui.h" // PrintAndLog
21 int ecdsa_asn1_get_signature(uint8_t *signature
, size_t signaturelen
, uint8_t *rval
, uint8_t *sval
) {
22 if (!signature
|| !signaturelen
|| !rval
|| !sval
)
26 unsigned char *p
= signature
;
27 const unsigned char *end
= p
+ signaturelen
;
31 if ((res
= mbedtls_asn1_get_tag(&p
, end
, &len
, MBEDTLS_ASN1_CONSTRUCTED
| MBEDTLS_ASN1_SEQUENCE
)) == 0) {
32 mbedtls_mpi_init(&xmpi
);
33 res
= mbedtls_asn1_get_mpi(&p
, end
, &xmpi
);
35 mbedtls_mpi_free(&xmpi
);
39 res
= mbedtls_mpi_write_binary(&xmpi
, rval
, 32);
40 mbedtls_mpi_free(&xmpi
);
44 mbedtls_mpi_init(&xmpi
);
45 res
= mbedtls_asn1_get_mpi(&p
, end
, &xmpi
);
47 mbedtls_mpi_free(&xmpi
);
51 res
= mbedtls_mpi_write_binary(&xmpi
, sval
, 32);
52 mbedtls_mpi_free(&xmpi
);
65 static bool print_cb(void *data
, const struct tlv
*tlv
, int level
, bool is_leaf
) {
67 asn1_tag_dump(tlv
, stdout
, level
, &candump
);
68 if (is_leaf
&& candump
) {
69 dump_buffer(tlv
->value
, tlv
->len
, stdout
, level
);
75 int asn1_print(uint8_t *asn1buf
, size_t asn1buflen
, char *indent
) {
77 struct tlvdb
*t
= NULL
;
78 t
= tlvdb_parse_multi(asn1buf
, asn1buflen
);
80 tlvdb_visit(t
, print_cb
, NULL
, 0);
83 PrintAndLogEx(ERR
, "Can't parse data as TLV tree.");