]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/crypto/asn1utils.c
2a3fe698bad276a4d4d608ee453d5d23d438dfe4
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"
12 #include <mbedtls/asn1.h>
14 int ecdsa_asn1_get_signature(uint8_t *signature
, size_t signaturelen
, uint8_t *rval
, uint8_t *sval
) {
15 if (!signature
|| !signaturelen
|| !rval
|| !sval
)
19 unsigned char *p
= signature
;
20 const unsigned char *end
= p
+ signaturelen
;
24 if ((res
= mbedtls_asn1_get_tag(&p
, end
, &len
, MBEDTLS_ASN1_CONSTRUCTED
| MBEDTLS_ASN1_SEQUENCE
)) == 0) {
25 mbedtls_mpi_init(&xmpi
);
26 res
= mbedtls_asn1_get_mpi(&p
, end
, &xmpi
);
28 mbedtls_mpi_free(&xmpi
);
32 res
= mbedtls_mpi_write_binary(&xmpi
, rval
, 32);
33 mbedtls_mpi_free(&xmpi
);
37 mbedtls_mpi_init(&xmpi
);
38 res
= mbedtls_asn1_get_mpi(&p
, end
, &xmpi
);
40 mbedtls_mpi_free(&xmpi
);
44 res
= mbedtls_mpi_write_binary(&xmpi
, sval
, 32);
45 mbedtls_mpi_free(&xmpi
);
58 int asn1_print(uint8_t *asn1buf
, int level
) {