blob: 707f138d44a4e7e47b0a2643a9d37686c2ba21e9 [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. */
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +020031#define POLARSSL_ERR_PK_TYPE_MISMATCH -0x2F00 /**< Type mismatch, eg attempt to use a RSA key as EC, or to modify key type */
Manuel Pégourié-Gonnard7a6c9462013-07-09 10:04:07 +020032
Paul Bakkered27a042013-04-18 22:46:23 +020033#ifdef __cplusplus
34extern "C" {
35#endif
36
37/**
38 * \brief Public key types
39 */
40typedef enum {
41 POLARSSL_PK_NONE=0,
Manuel Pégourié-Gonnard81c313c2013-07-09 10:35:54 +020042#if defined(POLARSSL_RSA_C)
Paul Bakkered27a042013-04-18 22:46:23 +020043 POLARSSL_PK_RSA,
Manuel Pégourié-Gonnard81c313c2013-07-09 10:35:54 +020044#endif
45#if defined(POLARSSL_ECP_C)
Manuel Pégourié-Gonnard5a9b82e2013-07-01 16:57:44 +020046 POLARSSL_PK_ECKEY,
47 POLARSSL_PK_ECKEY_DH,
Manuel Pégourié-Gonnard81c313c2013-07-09 10:35:54 +020048#endif
Paul Bakkered27a042013-04-18 22:46:23 +020049} pk_type_t;
50
Manuel Pégourié-Gonnard12e0ed92013-07-04 13:31:32 +020051/**
52 * \brief Public key container
53 */
54typedef struct
55{
56 pk_type_t type; /**< Public key type */
57 void * data; /**< Public key data */
58} pk_context;
59
60/**
61 * \brief Initialize a pk_context (as NONE)
62 */
63void pk_init( pk_context *ctx );
64
65/**
66 * \brief Free a pk_context
67 */
68void pk_free( pk_context *ctx );
69
70/**
71 * \brief Set a pk_context to a given type
72 *
73 * \param ctx Context to initialize
74 * \param type Type of key
75 *
Manuel Pégourié-Gonnard374e4b82013-07-09 10:21:34 +020076 * \note Once the type of a key has been set, it cannot be reset.
77 * If you want to do so, you need to use pk_free() first.
78 *
79 * \return O on success,
80 * POLARSSL_ERR_PK_MALLOC_FAILED on memory allocation fail,
81 * POLARSSL_ERR_PK_TYPE_MISMATCH on attempts to reset type.
Manuel Pégourié-Gonnard12e0ed92013-07-04 13:31:32 +020082 */
83int pk_set_type( pk_context *ctx, pk_type_t type );
84
Paul Bakkered27a042013-04-18 22:46:23 +020085#ifdef __cplusplus
86}
87#endif
88
89#endif /* pk.h */