VirtualBox

source: vbox/trunk/include/iprt/crypto/key.h@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1/** @file
2 * IPRT - Cryptographic Keys
3 */
4
5/*
6 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_crypto_key_h
37#define IPRT_INCLUDED_crypto_key_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/crypto/x509.h>
43#include <iprt/crypto/taf.h>
44#include <iprt/sha.h>
45
46
47RT_C_DECLS_BEGIN
48
49struct RTCRPEMSECTION;
50struct RTCRX509SUBJECTPUBLICKEYINFO;
51
52/** @defgroup grp_rt_crkey RTCrKey - Crypotgraphic Keys.
53 * @ingroup grp_rt_crypto
54 * @{
55 */
56
57/**
58 * Key types.
59 */
60typedef enum RTCRKEYTYPE
61{
62 /** Invalid zero value. */
63 RTCRKEYTYPE_INVALID = 0,
64 /** RSA private key. */
65 RTCRKEYTYPE_RSA_PRIVATE,
66 /** RSA public key. */
67 RTCRKEYTYPE_RSA_PUBLIC,
68 /** End of key types. */
69 RTCRKEYTYPE_END,
70 /** The usual type size hack. */
71 RTCRKEYTYPE_32BIT_HACK = 0x7fffffff
72} RTCRKEYTYPE;
73
74
75RTDECL(int) RTCrKeyCreateFromSubjectPublicKeyInfo(PRTCRKEY phKey, struct RTCRX509SUBJECTPUBLICKEYINFO const *pSrc,
76 PRTERRINFO pErrInfo, const char *pszErrorTag);
77RTDECL(int) RTCrKeyCreateFromPublicAlgorithmAndBits(PRTCRKEY phKey, PCRTASN1OBJID pAlgorithm,
78 PCRTASN1BITSTRING pPublicKey,
79 PRTERRINFO pErrInfo, const char *pszErrorTag);
80RTDECL(int) RTCrKeyCreateFromPemSection(PRTCRKEY phKey, uint32_t fFlags, struct RTCRPEMSECTION const *pSection,
81 const char *pszPassword, PRTERRINFO pErrInfo, const char *pszErrorTag);
82RTDECL(int) RTCrKeyCreateFromBuffer(PRTCRKEY phKey, uint32_t fFlags, void const *pvSrc, size_t cbSrc,
83 const char *pszPassword, PRTERRINFO pErrInfo, const char *pszErrorTag);
84RTDECL(int) RTCrKeyCreateFromFile(PRTCRKEY phKey, uint32_t fFlags, const char *pszFilename,
85 const char *pszPassword, PRTERRINFO pErrInfo);
86/** @todo add support for decrypting private keys. */
87/** @name RTCRKEYFROM_F_XXX
88 * @{ */
89/** Only PEM sections, no binary fallback.
90 * @sa RTCRPEMREADFILE_F_ONLY_PEM */
91#define RTCRKEYFROM_F_ONLY_PEM RT_BIT(1)
92/** Valid flags. */
93#define RTCRKEYFROM_F_VALID_MASK UINT32_C(0x00000002)
94/** @} */
95
96RTDECL(int) RTCrKeyCreateNewRsa(PRTCRKEY phKey, uint32_t cBits, uint32_t uPubExp, uint32_t fFlags);
97
98
99RTDECL(uint32_t) RTCrKeyRetain(RTCRKEY hKey);
100RTDECL(uint32_t) RTCrKeyRelease(RTCRKEY hKey);
101RTDECL(RTCRKEYTYPE) RTCrKeyGetType(RTCRKEY hKey);
102RTDECL(bool) RTCrKeyHasPrivatePart(RTCRKEY hKey);
103RTDECL(bool) RTCrKeyHasPublicPart(RTCRKEY hKey);
104RTDECL(uint32_t) RTCrKeyGetBitCount(RTCRKEY hKey);
105RTDECL(int) RTCrKeyQueryRsaModulus(RTCRKEY hKey, PRTBIGNUM pModulus);
106RTDECL(int) RTCrKeyQueryRsaPrivateExponent(RTCRKEY hKey, PRTBIGNUM pPrivateExponent);
107
108/** Public key markers. */
109extern RT_DECL_DATA_CONST(RTCRPEMMARKER const) g_aRTCrKeyPublicMarkers[];
110/** Number of entries in g_aRTCrKeyPublicMarkers. */
111extern RT_DECL_DATA_CONST(uint32_t const) g_cRTCrKeyPublicMarkers;
112/** Private key markers. */
113extern RT_DECL_DATA_CONST(RTCRPEMMARKER const) g_aRTCrKeyPrivateMarkers[];
114/** Number of entries in g_aRTCrKeyPrivateMarkers. */
115extern RT_DECL_DATA_CONST(uint32_t const) g_cRTCrKeyPrivateMarkers;
116/** Private and public key markers. */
117extern RT_DECL_DATA_CONST(RTCRPEMMARKER const) g_aRTCrKeyAllMarkers[];
118/** Number of entries in g_aRTCrKeyAllMarkers. */
119extern RT_DECL_DATA_CONST(uint32_t const) g_cRTCrKeyAllMarkers;
120
121/** @} */
122
123RT_C_DECLS_END
124
125#endif /* !IPRT_INCLUDED_crypto_key_h */
126
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette