S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
sopc_crypto_provider.h
Go to the documentation of this file.
1/*
2 * Licensed to Systerel under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work
4 * for additional information regarding copyright ownership.
5 * Systerel licenses this file to you under the Apache
6 * License, Version 2.0 (the "License"); you may not use this
7 * file except in compliance with the License. You may obtain
8 * a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
26#ifndef SOPC_CRYPTO_PROVIDER_H_
27#define SOPC_CRYPTO_PROVIDER_H_
28
29#include "sopc_crypto_decl.h"
30#include "sopc_enums.h"
31#include "sopc_key_sets.h"
32#include "sopc_pki_decl.h"
33
64
65/* ------------------------------------------------------------------------------------------------
66 * CryptoProvider
67 * ------------------------------------------------------------------------------------------------
68 */
69
85
101
108
115
122
123/* ------------------------------------------------------------------------------------------------
124 * CryptoProvider get-length & uris operations
125 * ------------------------------------------------------------------------------------------------
126 */
127
143 uint32_t* pLength);
144
161 uint32_t lengthIn,
162 uint32_t* pLengthOut);
163
180 uint32_t lengthIn,
181 uint32_t* pLengthOut);
182
198 uint32_t* pLength);
199
213 uint32_t* pLength);
214
236 uint32_t* pCipherTextBlockSize,
237 uint32_t* pPlainTextBlockSize);
238
252 uint32_t* pLenNonce);
253
271 uint32_t* pSymmCryptoKeyLength,
272 uint32_t* pSymmSignKeyLength,
273 uint32_t* pSymmInitVectorLength);
274
292 const SOPC_AsymmetricKey* pKey,
293 uint32_t* pLenKeyBytes);
294
309 uint32_t* length);
310
330 const SOPC_AsymmetricKey* pKey,
331 uint32_t* pCipherTextBlockSize,
332 uint32_t* pPlainTextBlockSize);
333
351 const SOPC_AsymmetricKey* pKey,
352 uint32_t lengthIn,
353 uint32_t* pLengthOut);
354
373 const SOPC_AsymmetricKey* pKey,
374 uint32_t lengthIn,
375 uint32_t* pLengthOut);
376
393 const SOPC_AsymmetricKey* pKey,
394 uint32_t* pLength);
395
406
421 uint32_t* pLength);
422
439
456 uint32_t* pLength);
457
458/* ------------------------------------------------------------------------------------------------
459 * Symmetric cryptography
460 * ------------------------------------------------------------------------------------------------
461 */
462
491 const uint8_t* pInput,
492 uint32_t lenPlainText,
493 const SOPC_SecretBuffer* pKey,
494 const SOPC_SecretBuffer* pIV,
495 uint8_t* pOutput,
496 uint32_t lenOutput);
497
528 const uint8_t* pInput,
529 uint32_t lenCipherText,
530 const SOPC_SecretBuffer* pKey,
531 const SOPC_SecretBuffer* pIV,
532 uint8_t* pOutput,
533 uint32_t lenOutput);
534
568 const uint8_t* pInput,
569 uint32_t lenInput,
570 const SOPC_SecretBuffer* pKey,
571 const SOPC_SecretBuffer* pKeyNonce,
572 const SOPC_ExposedBuffer* pRandom,
573 uint32_t lenRandom,
574 uint32_t uSequenceNumber,
575 uint8_t* pOutput,
576 uint32_t lenOutput);
577
605 const uint8_t* pInput,
606 uint32_t lenInput,
607 const SOPC_SecretBuffer* pKey,
608 uint8_t* pOutput,
609 uint32_t lenOutput);
610
639 const uint8_t* pInput,
640 uint32_t lenInput,
641 const SOPC_SecretBuffer* pKey,
642 const uint8_t* pSignature,
643 uint32_t lenOutput);
644
645/* ------------------------------------------------------------------------------------------------
646 * Random and pseudo-random functionalities
647 * ------------------------------------------------------------------------------------------------
648 */
649
672 uint32_t nBytes,
673 SOPC_ExposedBuffer** ppBuffer);
674
694 SOPC_SecretBuffer** ppNonce);
695
711
721 const SOPC_ExposedBuffer* pSecret,
722 uint32_t lenSecret,
723 const SOPC_ExposedBuffer* pSeed,
724 uint32_t lenSeed,
725 SOPC_ExposedBuffer* pOutput,
726 uint32_t lenOutput);
727
753 const SOPC_ExposedBuffer* pClientNonce,
754 uint32_t lenClientNonce,
755 const SOPC_ExposedBuffer* pServerNonce,
756 uint32_t lenServerNonce,
757 SOPC_SC_SecurityKeySet* pClientKeySet,
758 SOPC_SC_SecurityKeySet* pServerKeySet);
759
783 const SOPC_SecretBuffer* pClientNonce,
784 const SOPC_ExposedBuffer* pServerNonce,
785 uint32_t lenServerNonce,
786 SOPC_SC_SecurityKeySet* pClientKeySet,
787 SOPC_SC_SecurityKeySet* pServerKeySet);
788
812 const SOPC_ExposedBuffer* pClientNonce,
813 uint32_t lenClientNonce,
814 SOPC_SecretBuffer* pServerNonce,
815 SOPC_SC_SecurityKeySet* pClientKeySet,
816 SOPC_SC_SecurityKeySet* pServerKeySet);
817
818/* ------------------------------------------------------------------------------------------------
819 * Asymmetric cryptography
820 * ------------------------------------------------------------------------------------------------
821 */
822
853 const uint8_t* pInput,
854 uint32_t lenInput,
855 const SOPC_AsymmetricKey* pKey,
856 uint8_t* pOutput,
857 uint32_t lenOutput,
858 const char** errorReason);
859
893 const uint8_t* pInput,
894 uint32_t lenInput,
895 const SOPC_AsymmetricKey* pKey,
896 uint8_t* pOutput,
897 uint32_t lenOutput,
898 uint32_t* pLenWritten,
899 const char** errorReason);
900
938 const uint8_t* pInput,
939 uint32_t lenInput,
940 const SOPC_AsymmetricKey* pKeyPrivateLocal,
941 uint8_t* pSignature,
942 uint32_t lenSignature,
943 const char** errorReason);
944
977 const uint8_t* pInput,
978 uint32_t lenInput,
979 const SOPC_AsymmetricKey* pKeyRemotePublic,
980 const uint8_t* pSignature,
981 uint32_t lenSignature,
982 const char** errorReason);
983
984/* ------------------------------------------------------------------------------------------------
985 * Certificate validation
986 * ------------------------------------------------------------------------------------------------
987 */
988
1012 SOPC_PKIProvider* pPKI,
1013 const SOPC_PKI_Type PKIType,
1014 const SOPC_CertificateList* pCert,
1015 uint32_t* error);
1016
1017#endif /* SOPC_CRYPTO_PROVIDER_H_ */
Defines the common declarations for the cryptographic objects. The structures and macros defined in t...
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricEncrypt(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenPlainText, const SOPC_SecretBuffer *pKey, const SOPC_SecretBuffer *pIV, uint8_t *pOutput, uint32_t lenOutput)
Encrypts a padded payload pInput of lenPlainText bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricGetLength_Encryption(const SOPC_CryptoProvider *pProvider, const SOPC_AsymmetricKey *pKey, uint32_t lengthIn, uint32_t *pLengthOut)
Calculates the size of the required output buffer to cipher lengthIn bytes through asymmetric encrypt...
SOPC_ReturnStatus SOPC_CryptoProvider_Certificate_Validate(const SOPC_CryptoProvider *pProvider, SOPC_PKIProvider *pPKI, const SOPC_PKI_Type PKIType, const SOPC_CertificateList *pCert, uint32_t *error)
Validates the given Certificate pCert.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricVerify(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenInput, const SOPC_SecretBuffer *pKey, const uint8_t *pSignature, uint32_t lenOutput)
Verifies the signature pSignature of the payload pInput of lenInput bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricGetLength_Msgs(const SOPC_CryptoProvider *pProvider, const SOPC_AsymmetricKey *pKey, uint32_t *pCipherTextBlockSize, uint32_t *pPlainTextBlockSize)
Provides the lengths in bytes of the messages used in asymmetric encryption process.
SOPC_ReturnStatus SOPC_CryptoProvider_DeriveKeySetsServer(const SOPC_CryptoProvider *pProvider, const SOPC_ExposedBuffer *pClientNonce, uint32_t lenClientNonce, SOPC_SecretBuffer *pServerNonce, SOPC_SC_SecurityKeySet *pClientKeySet, SOPC_SC_SecurityKeySet *pServerKeySet)
Derive pseudo-random key sets from the randomly generated and shared secrets.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricGetLength_KeyBytes(const SOPC_CryptoProvider *pProvider, const SOPC_AsymmetricKey *pKey, uint32_t *pLenKeyBytes)
Writes the length in bytes in pLenKeyBytes of the asymmetric key pKey.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricDecrypt(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenInput, const SOPC_AsymmetricKey *pKey, uint8_t *pOutput, uint32_t lenOutput, uint32_t *pLenWritten, const char **errorReason)
Decrypts a payload pInput of lenInput bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricGetLength_Encryption(const SOPC_CryptoProvider *pProvider, uint32_t lengthIn, uint32_t *pLengthOut)
Writes the length in bytes in pLengthOut of an encrypted message of lengthIn bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_GenerateRandomBytes(const SOPC_CryptoProvider *pProvider, uint32_t nBytes, SOPC_ExposedBuffer **ppBuffer)
Generates truly random data of arbitrary length.
SOPC_CryptoProvider * SOPC_CryptoProvider_CreatePubSub(const char *uri)
Creates an initialized SOPC_CryptoProvider context for PubSub exchanges from a string containing the ...
SOPC_ReturnStatus SOPC_CryptoProvider_PubSubCrypt(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenInput, const SOPC_SecretBuffer *pKey, const SOPC_SecretBuffer *pKeyNonce, const SOPC_ExposedBuffer *pRandom, uint32_t lenRandom, uint32_t uSequenceNumber, uint8_t *pOutput, uint32_t lenOutput)
Encrypts or Decrypts a payload pInput of lenInput bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricSign(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenInput, const SOPC_SecretBuffer *pKey, uint8_t *pOutput, uint32_t lenOutput)
Signs a payload pInput of lenInput bytes, writes the signature in pOutput of lenOutput bytes.
const char * SOPC_CryptoProvider_AsymmetricGetUri_SignAlgorithm(const SOPC_CryptoProvider *pProvider)
Returns the URI of the AsymetricSignatureAlgorithm.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricGetLength_Decryption(const SOPC_CryptoProvider *pProvider, uint32_t lengthIn, uint32_t *pLengthOut)
Writes the length in bytes in pLengthOut of a decrypted message of lengthIn bytes.
SOPC_CryptoProvider * SOPC_CryptoProvider_Create(const char *uri)
Creates an initialized SOPC_CryptoProvider context for a client-server connection from a string conta...
SOPC_ReturnStatus SOPC_CryptoProvider_GenerateSecureChannelNonce(const SOPC_CryptoProvider *pProvider, SOPC_SecretBuffer **ppNonce)
Generates a single truly random nonce for the SecureChannel creation.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricGetLength_CryptoKey(const SOPC_CryptoProvider *pProvider, uint32_t *pLength)
Writes the length in bytes in pLength of the key used for symmetric encryption/decryption.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricGetLength_Blocks(const SOPC_CryptoProvider *pProvider, uint32_t *pCipherTextBlockSize, uint32_t *pPlainTextBlockSize)
Provides the lengths in bytes of the blocks used in the symmetric encryption process.
const SOPC_CryptoProfile_PubSub * SOPC_CryptoProvider_GetProfilePubSub(const SOPC_CryptoProvider *pProvider)
Returns the non NULL PubSub crypto profile but returns NULL if the client-server profile is non NULL.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricGetLength_Signature(const SOPC_CryptoProvider *pProvider, const SOPC_AsymmetricKey *pKey, uint32_t *pLength)
Calculates the size of the required output buffer to contain the asymmetric signature.
SOPC_ReturnStatus SOPC_CryptoProvider_DeriveKeySetsClient(const SOPC_CryptoProvider *pProvider, const SOPC_SecretBuffer *pClientNonce, const SOPC_ExposedBuffer *pServerNonce, uint32_t lenServerNonce, SOPC_SC_SecurityKeySet *pClientKeySet, SOPC_SC_SecurityKeySet *pServerKeySet)
Derive pseudo-random key sets from the randomly generated and shared secrets.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricGetLength_SecureChannelNonce(const SOPC_CryptoProvider *pProvider, uint32_t *pLenNonce)
Provides the length in bytes of the SecureChannel nonces used in the symmetric encryption process.
SOPC_ReturnStatus SOPC_CryptoProvider_DeriveKeySets(const SOPC_CryptoProvider *pProvider, const SOPC_ExposedBuffer *pClientNonce, uint32_t lenClientNonce, const SOPC_ExposedBuffer *pServerNonce, uint32_t lenServerNonce, SOPC_SC_SecurityKeySet *pClientKeySet, SOPC_SC_SecurityKeySet *pServerKeySet)
Derive pseudo-random key sets from the randomly generated and shared secrets.
SOPC_ReturnStatus SOPC_CryptoProvider_DeriveGetLengths(const SOPC_CryptoProvider *pProvider, uint32_t *pSymmCryptoKeyLength, uint32_t *pSymmSignKeyLength, uint32_t *pSymmInitVectorLength)
Provides the lengths in bytes of the secrets derived from the nonce exchange.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricGetLength_Signature(const SOPC_CryptoProvider *pProvider, uint32_t *pLength)
Provides the length in bytes of the symmetric signature message.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricGetLength_Decryption(const SOPC_CryptoProvider *pProvider, const SOPC_AsymmetricKey *pKey, uint32_t lengthIn, uint32_t *pLengthOut)
Calculates the size of the required output buffer to decipher lengthIn bytes through asymmetric decry...
SOPC_ReturnStatus SOPC_CryptoProvider_DerivePseudoRandomData(const SOPC_CryptoProvider *pProvider, const SOPC_ExposedBuffer *pSecret, uint32_t lenSecret, const SOPC_ExposedBuffer *pSeed, uint32_t lenSeed, SOPC_ExposedBuffer *pOutput, uint32_t lenOutput)
Derives pseudo-random data from the randomly generated and shared secrets.
void SOPC_CryptoProvider_Free(SOPC_CryptoProvider *pCryptoProvider)
Frees a SOPC_CryptoProvider created with SOPC_CryptoProvider_Create().
SOPC_ReturnStatus SOPC_CryptoProvider_PubSubGetLength_KeyNonce(const SOPC_CryptoProvider *pProvider, uint32_t *pLength)
Writes the length in bytes in pLength of the key nonce used for PubSub encryption/decryption.
SOPC_ReturnStatus SOPC_CryptoProvider_GenerateRandomID(const SOPC_CryptoProvider *pProvider, uint32_t *pID)
Generates 4 bytes of truly random data.
SOPC_ReturnStatus SOPC_CryptoProvider_PubSubGetLength_MessageRandom(const SOPC_CryptoProvider *pProvider, uint32_t *pLength)
Writes the length in bytes in pLength of the random bytes used for PubSub encryption/decryption.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricVerify(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenInput, const SOPC_AsymmetricKey *pKeyRemotePublic, const uint8_t *pSignature, uint32_t lenSignature, const char **errorReason)
Verifies the signature pSignature of a payload pInput of lenInput bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_CertificateGetLength_Thumbprint(const SOPC_CryptoProvider *pProvider, uint32_t *pLength)
Calculates the size of the signature of the certificates.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricGetLength_SignKey(const SOPC_CryptoProvider *pProvider, uint32_t *pLength)
Writes the length in bytes in pLength of the key used for symmetric signature.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricEncrypt(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenInput, const SOPC_AsymmetricKey *pKey, uint8_t *pOutput, uint32_t lenOutput, const char **errorReason)
Encrypts a payload pInput of lenInput bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricSign(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenInput, const SOPC_AsymmetricKey *pKeyPrivateLocal, uint8_t *pSignature, uint32_t lenSignature, const char **errorReason)
Signs a payload pInput of lenInput bytes.
SOPC_ReturnStatus SOPC_CryptoProvider_AsymmetricGetLength_OAEPHashLength(const SOPC_CryptoProvider *pProvider, uint32_t *length)
Provides the length of the hash used for OAEP encryption/decryption.
SOPC_ReturnStatus SOPC_CryptoProvider_SymmetricDecrypt(const SOPC_CryptoProvider *pProvider, const uint8_t *pInput, uint32_t lenCipherText, const SOPC_SecretBuffer *pKey, const SOPC_SecretBuffer *pIV, uint8_t *pOutput, uint32_t lenOutput)
Decrypts a payload pInput of lenPlainText bytes into a padded deciphered payload pOutput.
const SOPC_CryptoProfile * SOPC_CryptoProvider_GetProfileServices(const SOPC_CryptoProvider *pProvider)
Returns the non NULL client-server crypto profile but returns NULL if the PubSub profile is non NULL.
enum _SOPC_ReturnStatus SOPC_ReturnStatus
Common enumerations for S2OPC.
Defines the common declarations for the PKI objects. The structures and macros defined in this file a...
SOPC_PKI_Type
Type of PKI.
Definition sopc_pki_decl.h:129
uint8_t SOPC_ExposedBuffer
Definition sopc_secret_buffer.h:36
struct SOPC_SecretBuffer SOPC_SecretBuffer
Definition sopc_secret_buffer.h:35
The asymmetric key representation.
Definition key_manager_cyclone.h:42
The signed public key representation.
Definition key_manager_cyclone.h:60
SOPC_CryptoProfiles_PubSub gather pointers to cryptographic functions of the security policies of OPC...
Definition sopc_crypto_profiles.h:205
SOPC_CryptoProfiles gather pointers to cryptographic functions of the security policies of OPC UA Ser...
Definition sopc_crypto_profiles.h:181
The SOPC_CryptoProvider context.
Definition sopc_crypto_provider.h:43
const SOPC_CryptoProfile_PubSub *const pProfilePubSub
Definition sopc_crypto_provider.h:57
SOPC_CryptolibContext * pCryptolibContext
Definition sopc_crypto_provider.h:62
const SOPC_CryptoProfile *const pProfile
Definition sopc_crypto_provider.h:50
Definition crypto_provider_cyclone.h:29
The PKIProvider object for the Public Key Infrastructure.
Definition sopc_pki_struct_lib_internal.h:39
Definition sopc_key_sets.h:26