blob: 00f8cfcb1bd4dedef6448b742641a37c373c983c [file] [log] [blame]
Paul Bakkered27a042013-04-18 22:46:23 +02001/**
2 * \file pk.h
3 *
4 * \brief Public Key abstraction layer
5 *
6 * Copyright (C) 2006-2013, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_PK_H
28#define POLARSSL_PK_H
29
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +020030#define POLARSSL_ERR_PK_MALLOC_FAILED -0x2F80 /**< Memory alloation failed. */
31
Paul Bakkered27a042013-04-18 22:46:23 +020032#ifdef __cplusplus
33extern "C" {
34#endif
35
36/**
37 * \brief Public key types
38 */
39typedef enum {
40 POLARSSL_PK_NONE=0,
Manuel Pégourié-Gonnard81c313c2013-07-09 10:35:54 +020041#if defined(POLARSSL_RSA_C)
Paul Bakkered27a042013-04-18 22:46:23 +020042 POLARSSL_PK_RSA,
Manuel Pégourié-Gonnard81c313c2013-07-09 10:35:54 +020043#endif
44#if defined(POLARSSL_ECP_C)
Manuel Pégourié-Gonnard5a9b82e2013-07-01 16:57:44 +020045 POLARSSL_PK_ECKEY,
46 POLARSSL_PK_ECKEY_DH,
Manuel Pégourié-Gonnard81c313c2013-07-09 10:35:54 +020047#endif
Paul Bakkered27a042013-04-18 22:46:23 +020048} pk_type_t;
49
Manuel Pégourié-Gonnard12e0ed92013-07-04 13:31:32 +020050/**
51 * \brief Public key container
52 */
53typedef struct
54{
55 pk_type_t type; /**< Public key type */
56 void * data; /**< Public key data */
57} pk_context;
58
59/**
60 * \brief Initialize a pk_context (as NONE)
61 */
62void pk_init( pk_context *ctx );
63
64/**
65 * \brief Free a pk_context
66 */
67void pk_free( pk_context *ctx );
68
69/**
70 * \brief Set a pk_context to a given type
71 *
72 * \param ctx Context to initialize
73 * \param type Type of key
74 *
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +020075 * \return O on success, or POLARSSL_ERR_PK_MALLOC_FAILED
Manuel Pégourié-Gonnard12e0ed92013-07-04 13:31:32 +020076 */
77int pk_set_type( pk_context *ctx, pk_type_t type );
78
Paul Bakkered27a042013-04-18 22:46:23 +020079#ifdef __cplusplus
80}
81#endif
82
83#endif /* pk.h */