2 * libopenemv - a library to work with EMV family of smart cards
3 * Copyright (C) 2015 Dmitry Eremin-Solenikov
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
21 #include "crypto_backend.h"
25 static struct crypto_backend
*crypto_backend
;
27 static bool crypto_init(void)
32 crypto_backend
= crypto_polarssl_init();
40 struct crypto_hash
*crypto_hash_open(enum crypto_algo_hash hash
)
42 struct crypto_hash
*ch
;
47 ch
= crypto_backend
->hash_open(hash
);
54 void crypto_hash_close(struct crypto_hash
*ch
)
59 void crypto_hash_write(struct crypto_hash
*ch
, const unsigned char *buf
, size_t len
)
61 ch
->write(ch
, buf
, len
);
64 unsigned char *crypto_hash_read(struct crypto_hash
*ch
)
69 size_t crypto_hash_get_size(const struct crypto_hash
*ch
)
71 return ch
->get_size(ch
);
74 struct crypto_pk
*crypto_pk_open(enum crypto_algo_pk pk
, ...)
83 cp
= crypto_backend
->pk_open(pk
, vl
);
92 struct crypto_pk
*crypto_pk_open_priv(enum crypto_algo_pk pk
, ...)
100 if (!crypto_backend
->pk_open_priv
)
104 cp
= crypto_backend
->pk_open_priv(pk
, vl
);
113 struct crypto_pk
*crypto_pk_genkey(enum crypto_algo_pk pk
, ...)
115 struct crypto_pk
*cp
;
121 if (!crypto_backend
->pk_genkey
)
125 cp
= crypto_backend
->pk_genkey(pk
, vl
);
134 void crypto_pk_close(struct crypto_pk
*cp
)
139 unsigned char *crypto_pk_encrypt(const struct crypto_pk
*cp
, const unsigned char *buf
, size_t len
, size_t *clen
)
141 return cp
->encrypt(cp
, buf
, len
, clen
);
144 unsigned char *crypto_pk_decrypt(const struct crypto_pk
*cp
, const unsigned char *buf
, size_t len
, size_t *clen
)
152 return cp
->decrypt(cp
, buf
, len
, clen
);
155 enum crypto_algo_pk
crypto_pk_get_algo(const struct crypto_pk
*cp
)
163 size_t crypto_pk_get_nbits(const struct crypto_pk
*cp
)
168 return cp
->get_nbits(cp
);
171 unsigned char *crypto_pk_get_parameter(const struct crypto_pk
*cp
, unsigned param
, size_t *plen
)
175 if (!cp
->get_parameter
)
178 return cp
->get_parameter(cp
, param
, plen
);