mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
mbedtls added
This commit is contained in:
parent
c75c0e4e52
commit
6ab12db7a0
113 changed files with 53771 additions and 9565 deletions
63
client/crypto/asn1utils.c
Normal file
63
client/crypto/asn1utils.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2018 Merlok
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// asn.1 utils
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "asn1utils.h"
|
||||
#include <mbedtls/asn1.h>
|
||||
|
||||
int ecdsa_asn1_get_signature(uint8_t *signature, size_t signaturelen, uint8_t *rval, uint8_t *sval) {
|
||||
if (!signature || !signaturelen || !rval || !sval)
|
||||
return 1;
|
||||
|
||||
int res = 0;
|
||||
unsigned char *p = signature;
|
||||
const unsigned char *end = p + signaturelen;
|
||||
size_t len;
|
||||
mbedtls_mpi xmpi;
|
||||
|
||||
if ((res = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) == 0) {
|
||||
mbedtls_mpi_init(&xmpi);
|
||||
res = mbedtls_asn1_get_mpi(&p, end, &xmpi);
|
||||
if (res) {
|
||||
mbedtls_mpi_free(&xmpi);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
res = mbedtls_mpi_write_binary(&xmpi, rval, 32);
|
||||
mbedtls_mpi_free(&xmpi);
|
||||
if (res)
|
||||
goto exit;
|
||||
|
||||
mbedtls_mpi_init(&xmpi);
|
||||
res = mbedtls_asn1_get_mpi(&p, end, &xmpi);
|
||||
if (res) {
|
||||
mbedtls_mpi_free(&xmpi);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
res = mbedtls_mpi_write_binary(&xmpi, sval, 32);
|
||||
mbedtls_mpi_free(&xmpi);
|
||||
if (res)
|
||||
goto exit;
|
||||
|
||||
// check size
|
||||
if (end != p)
|
||||
return 2;
|
||||
}
|
||||
|
||||
exit:
|
||||
return res;
|
||||
}
|
||||
|
||||
int asn1_print(uint8_t *asn1buf, int level) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue