1 | /** @file
|
---|
2 | * IPRT - Crypto - Symmetric Ciphers.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2018-2019 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_crypto_cipher_h
|
---|
27 | #define IPRT_INCLUDED_crypto_cipher_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/asn1.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | RT_C_DECLS_BEGIN
|
---|
36 |
|
---|
37 | struct RTCRX509SUBJECTPUBLICKEYINFO;
|
---|
38 |
|
---|
39 | /** @defgroup grp_rt_crcipher RTCrCipher - Symmetric Ciphers
|
---|
40 | * @ingroup grp_rt_crypto
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * A symmetric cipher handle.
|
---|
46 | *
|
---|
47 | * @remarks In OpenSSL terms this corresponds to a EVP_CIPHER, while in Microsoft
|
---|
48 | * terms it is an algorithm handle. The latter is why a handle was
|
---|
49 | * choosen rather than constant descriptor structure pointer. */
|
---|
50 | typedef struct RTCRCIPHERINT *RTCRCIPHER;
|
---|
51 | /** Pointer to a symmetric cipher handle. */
|
---|
52 | typedef RTCRCIPHER *PRTCRCIPHER;
|
---|
53 | /** Nil symmetric cipher handle. */
|
---|
54 | #define NIL_RTCRCIPHER ((RTCRCIPHER)0)
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Symmetric cipher types.
|
---|
58 | *
|
---|
59 | * @note Only add new types at the end, existing values must be stable.
|
---|
60 | */
|
---|
61 | typedef enum RTCRCIPHERTYPE
|
---|
62 | {
|
---|
63 | /** Invalid zero value. */
|
---|
64 | RTCRCIPHERTYPE_INVALID = 0,
|
---|
65 | /** XTS-AES-128 (NIST SP 800-38E). */
|
---|
66 | RTCRCIPHERTYPE_XTS_AES_128,
|
---|
67 | /** XTS-AES-256 (NIST SP 800-38E). */
|
---|
68 | RTCRCIPHERTYPE_XTS_AES_256,
|
---|
69 | /** End of valid symmetric cipher types. */
|
---|
70 | RTCRCIPHERTYPE_END,
|
---|
71 | /** Make sure the type is a 32-bit one. */
|
---|
72 | RTCRCIPHERTYPE_32BIT_HACK = 0x7fffffff
|
---|
73 | } RTCRCIPHERTYPE;
|
---|
74 |
|
---|
75 |
|
---|
76 | RTDECL(int) RTCrCipherOpenByType(PRTCRCIPHER phCipher, RTCRCIPHERTYPE enmType, uint32_t fFlags);
|
---|
77 | RTDECL(uint32_t) RTCrCipherRetain(RTCRCIPHER hCipher);
|
---|
78 | RTDECL(uint32_t) RTCrCipherRelease(RTCRCIPHER hCipher);
|
---|
79 | RTDECL(uint32_t) RTCrCipherGetKeyLength(RTCRCIPHER hCipher);
|
---|
80 | RTDECL(uint32_t) RTCrCipherGetInitializationVectorLength(RTCRCIPHER hCipher);
|
---|
81 | RTDECL(uint32_t) RTCrCipherGetBlockSize(RTCRCIPHER hCipher);
|
---|
82 |
|
---|
83 | RTDECL(int) RTCrCipherEncrypt(RTCRCIPHER hCipher, void const *pvKey, size_t cbKey,
|
---|
84 | void const *pvInitVector, size_t cbInitVector,
|
---|
85 | void const *pvPlainText, size_t cbPlainText,
|
---|
86 | void *pvEncrypted, size_t cbEncrypted, size_t *pcbEncrypted);
|
---|
87 | RTDECL(int) RTCrCipherDecrypt(RTCRCIPHER hCipher, void const *pvKey, size_t cbKey,
|
---|
88 | void const *pvInitVector, size_t cbInitVector,
|
---|
89 | void const *pvEncrypted, size_t cbEncrypted,
|
---|
90 | void *pvPlainText, size_t cbPlainText, size_t *pcbPlainText);
|
---|
91 |
|
---|
92 | /** @} */
|
---|
93 |
|
---|
94 | RT_C_DECLS_END
|
---|
95 |
|
---|
96 | #endif
|
---|
97 |
|
---|