1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/crypto/weakcrypto/inc/pbencryptor.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,396 @@
1.4 +/*
1.5 +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* ** IMPORTANT ** PublishedPartner API's in this file are published to 3rd party developers via the
1.19 +* Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 + @publishedPartner
1.27 + @released
1.28 +*/
1.29 +
1.30 +#ifndef __PBENCRYPTOR_H__
1.31 +#define __PBENCRYPTOR_H__
1.32 +
1.33 +#include "pbe.h"
1.34 +#include "padding.h"
1.35 +#include "msymmetriccipher.h"
1.36 +
1.37 +/**
1.38 + * Implements the password based encryption of elements.
1.39 + *
1.40 + * @see CPBEncryptElement
1.41 + * @since v7.0s
1.42 + */
1.43 +class CPBEncryptorElement : public CPBEncryptor
1.44 + {
1.45 +public:
1.46 + /**
1.47 + * Creates a new CPBEncryptorElement object from the specified cipher,
1.48 + * key, and Initialization Vector (IV).
1.49 + *
1.50 + * @param aCipher The encryption cipher
1.51 + * @param aKey The encryption key
1.52 + * @param aIV The Initialization Vector
1.53 + * @return A pointer to the new CPBEncryptorElement object
1.54 + */
1.55 + IMPORT_C static CPBEncryptorElement* NewL(TPBECipher aCipher,
1.56 + const TDesC8& aKey, const TDesC8& aIV);
1.57 +
1.58 + /**
1.59 + * Creates a new CPBEncryptorElement object from the specified cipher,
1.60 + * key, and IV.
1.61 + *
1.62 + * Puts a pointer to the returned object onto the cleanup stack.
1.63 + *
1.64 + * @param aCipher The encryption cipher
1.65 + * @param aKey The encryption key
1.66 + * @param aIV The Initialization Vector
1.67 + * @return A pointer to the new CPBEncryptorElement object
1.68 + */
1.69 + IMPORT_C static CPBEncryptorElement* NewLC(TPBECipher aCipher,
1.70 + const TDesC8& aKey, const TDesC8& aIV);
1.71 +
1.72 + /**
1.73 + * Transforms aInput into its encrypted form, aOutput.
1.74 + *
1.75 + * aOutput must have CPBEncryptorElement::MaxOutputLength() empty bytes remaining in its length.
1.76 + *
1.77 + * See the Cryptography api-guide documentation for an explanation of
1.78 + * how buffering of data supplied to this function is handled.
1.79 + *
1.80 + * @param aInput The plaintext.
1.81 + * @param aOutput The ciphertext.
1.82 + */
1.83 + void Process(const TDesC8& aInput, TDes8& aOutput);
1.84 +
1.85 + /**
1.86 + * Transforms aInput into its encrypted form, aOutput, and applies a
1.87 + * padding scheme to ensure a block aligned result.
1.88 + *
1.89 + * aOutput must have CPBEncryptorElement::MaxFinalOutputLength()
1.90 + * empty bytes remaining in its length.
1.91 + *
1.92 + * See the Cryptography api-guide documentation for an explanation of
1.93 + * how buffering of data supplied to this function is handled.
1.94 + *
1.95 + * @param aInput The plaintext.
1.96 + * @param aOutput The ciphertext.
1.97 + */
1.98 + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
1.99 +
1.100 + /**
1.101 + * Gets the maximum size of the output resulting from calling Process() with a
1.102 + * given input length.
1.103 + *
1.104 + * @param aMaxInputLength The maximum input length in bytes.
1.105 + * @return The maximum output length in bytes.
1.106 + */
1.107 + TInt MaxOutputLength(TUint aMaxInputLength) const;
1.108 +
1.109 + /**
1.110 + * Gets the maximum size of the output resulting from calling ProcessFinalL()
1.111 + * with a given input length.
1.112 + *
1.113 + * @param aMaxInputLength The maximum input length in bytes.
1.114 + * @return TInt The maximum output length in bytes.
1.115 + */
1.116 + TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
1.117 +
1.118 + /** Destructor */
1.119 + virtual ~CPBEncryptorElement();
1.120 +protected:
1.121 + /* @internalComponent */
1.122 + CPBEncryptorElement();
1.123 + /* @internalComponent */
1.124 + void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
1.125 +private:
1.126 + CSymmetricCipher* iCipher;
1.127 + };
1.128 +
1.129 +/**
1.130 + * Implements the password based decryption of elements.
1.131 + *
1.132 + * @since v7.0s
1.133 + */
1.134 +class CPBDecryptorElement : public CPBDecryptor
1.135 + {
1.136 +public:
1.137 + /**
1.138 + * Creates a new CPBDecryptorElement object from the specified cipher,
1.139 + * key, and IV.
1.140 + *
1.141 + * @param aCipher The decryption cipher
1.142 + * @param aKey The decryption key
1.143 + * @param aIV The Initialization Vector
1.144 + * @return A pointer to the new CPBDecryptorElement object
1.145 + */
1.146 + IMPORT_C static CPBDecryptorElement* NewL(const TPBECipher aCipher,
1.147 + const TDesC8& aKey, const TDesC8& aIV);
1.148 +
1.149 + /**
1.150 + * Creates a new CPBDecryptorElement object from the specified cipher,
1.151 + * key, and IV.
1.152 + *
1.153 + * Puts a pointer to the returned object onto the cleanup stack.
1.154 + *
1.155 + * @param aCipher The decryption cipher
1.156 + * @param aKey The decryption key
1.157 + * @param aIV The Initialization Vector
1.158 + * @return A pointer to the new CPBDecryptorElement object
1.159 + */
1.160 + IMPORT_C static CPBDecryptorElement* NewLC(const TPBECipher aCipher,
1.161 + const TDesC8& aKey, const TDesC8& aIV);
1.162 +
1.163 + /**
1.164 + * Transforms aInput into its decrypted form, aOutput.
1.165 + *
1.166 + * aOutput must have CPBDecryptorElement::MaxOutputLength() empty bytes
1.167 + * remaining in its length.
1.168 + *
1.169 + * See the Cryptography api-guide documentation for an explanation of
1.170 + * how buffering of data supplied to this function is handled.
1.171 + *
1.172 + * @param aInput The ciphertext.
1.173 + * @param aOutput The plaintext.
1.174 + */
1.175 + void Process(const TDesC8& aInput, TDes8& aOutput);
1.176 +
1.177 + /**
1.178 + * Transforms aInput into its decrypted form, aOutput.
1.179 + *
1.180 + * aOutput must have CPBDecryptorElement::MaxFinalOutputLength()
1.181 + * empty bytes remaining in its length.
1.182 + *
1.183 + * @param aInput The ciphertext.
1.184 + * @param aOutput The plaintext.
1.185 + */
1.186 + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
1.187 +
1.188 + /**
1.189 + * Gets the maximum size of the output given a certain input length.
1.190 + *
1.191 + * @param aMaxInputLength The maximum input length in bytes.
1.192 + * @return The maximum output length in bytes.
1.193 + */
1.194 + TInt MaxOutputLength(TUint aMaxInputLength) const;
1.195 +
1.196 + /**
1.197 + * Gets the maximum size of the output given a certain input length.
1.198 + *
1.199 + * @param aMaxInputLength The maximum input length in bytes.
1.200 + * @return The maximum output length in bytes.
1.201 + */
1.202 + TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
1.203 +
1.204 + /** Destructor */
1.205 + virtual ~CPBDecryptorElement();
1.206 +protected:
1.207 + /* @internalComponent */
1.208 + CPBDecryptorElement();
1.209 + /* @internalComponent */
1.210 + void ConstructL(const TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
1.211 +private:
1.212 + CSymmetricCipher* iCipher;
1.213 + };
1.214 +
1.215 +/**
1.216 + * Implements the password based encryption of multiple elements.
1.217 + *
1.218 + * @see CPBEncryptSet
1.219 + * @since v7.0s
1.220 + */
1.221 +class CPBEncryptorSet : public CPBEncryptor
1.222 + {
1.223 +public:
1.224 + /**
1.225 + * Creates a new CPBEncryptorSet object from the specified cipher and key,
1.226 + * and a random Initialization Vector (IV).
1.227 + *
1.228 + * @param aCipher The encryption cipher
1.229 + * @param aKey The encryption key
1.230 + * @return A pointer to the new CPBEncryptorSet object
1.231 + */
1.232 + IMPORT_C static CPBEncryptorSet* NewL(const TPBECipher aCipher,
1.233 + const TDesC8& aKey);
1.234 +
1.235 + /**
1.236 + * Creates a new CPBEncryptorSet object from the specified cipher and key,
1.237 + * and a random IV.
1.238 + *
1.239 + * Puts a pointer to the returned object onto the cleanup stack.
1.240 + *
1.241 + * @param aCipher The encryption cipher
1.242 + * @param aKey The encryption key
1.243 + * @return A pointer to the new CPBEncryptorSet object
1.244 + */
1.245 + IMPORT_C static CPBEncryptorSet* NewLC(const TPBECipher aCipher,
1.246 + const TDesC8& aKey);
1.247 +
1.248 + /**
1.249 + * Resets the CPBEncryptorSet object back to its original state
1.250 + * and clears all its buffers.
1.251 + */
1.252 + IMPORT_C void Reset(void);
1.253 +
1.254 + /**
1.255 + * Transforms aInput into its encrypted form, aOutput.
1.256 + *
1.257 + * aOutput must have CPBEncryptorSet::MaxOutputLength() empty bytes
1.258 + * remaining in its length.
1.259 + *
1.260 + * @param aInput The plaintext.
1.261 + * @param aOutput The ciphertext.
1.262 + */
1.263 + void Process(const TDesC8& aInput, TDes8& aOutput);
1.264 +
1.265 + /**
1.266 + * Transforms aInput into its encrypted form, aOutput, and applies a
1.267 + * padding scheme to ensure a block aligned result.
1.268 + *
1.269 + * aOutput must have CPBEncryptorSet::MaxFinalOutputLength()
1.270 + * empty bytes remaining in its length.
1.271 + *
1.272 + * @param aInput The plaintext.
1.273 + * @param aOutput The ciphertext.
1.274 + */
1.275 + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
1.276 +
1.277 + /**
1.278 + * Gets the maximum size of the output given a certain input length.
1.279 + *
1.280 + * @param aMaxInputLength The maximum input length in bytes.
1.281 + * @return The maximum output length in bytes.
1.282 + */
1.283 + TInt MaxOutputLength(TUint aMaxInputLength) const;
1.284 +
1.285 + /**
1.286 + * Gets the maximum size of the output given a certain input length.
1.287 + *
1.288 + * @param aMaxInputLength The maximum input length in bytes.
1.289 + * @return The maximum output length in bytes.
1.290 + */
1.291 + TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
1.292 +
1.293 + /** Destructor */
1.294 + virtual ~CPBEncryptorSet();
1.295 +protected:
1.296 + /* @internalComponent */
1.297 + CPBEncryptorSet();
1.298 + /* @internalComponent */
1.299 + void ConstructL(TPBECipher aCipher, const TDesC8& aKey);
1.300 +private:
1.301 + CSymmetricCipher* iCipher;
1.302 + HBufC8* iIV;
1.303 + TBool iIVSent;
1.304 + };
1.305 +
1.306 +
1.307 +/**
1.308 + * Implements the password based decryption of multiple elements.
1.309 + *
1.310 + * @since v7.0s
1.311 + */
1.312 +class CPBDecryptorSet : public CPBDecryptor
1.313 + {
1.314 +public:
1.315 + /**
1.316 + * Creates a new CPBDecryptorSet object from the specified cipher and key,
1.317 + * and a random IV.
1.318 + *
1.319 + * @param aCipher The decryption cipher
1.320 + * @param aKey The decryption key
1.321 + * @return A pointer to the new CPBDecryptorSet object
1.322 + */
1.323 + IMPORT_C static CPBDecryptorSet* NewL(const TPBECipher aCipher,
1.324 + const TDesC8& aKey);
1.325 +
1.326 + /**
1.327 + * Creates a new CPBDecryptorSet object from the specified cipher and key,
1.328 + * and a random IV.
1.329 + *
1.330 + * Puts a pointer to the returned object onto the cleanup stack.
1.331 + *
1.332 + * @param aCipher The decryption cipher
1.333 + * @param aKey The decryption key
1.334 + * @return A pointer to the new CPBDecryptorSet object
1.335 + */
1.336 + IMPORT_C static CPBDecryptorSet* NewLC(const TPBECipher aCipher,
1.337 + const TDesC8& aKey);
1.338 +
1.339 + /**
1.340 + * Resets the CPBDecryptorSet object back to its original state
1.341 + * and clears all its buffers.
1.342 + */
1.343 + IMPORT_C void Reset(void);
1.344 +
1.345 + /**
1.346 + * Transforms aInput into its decrypted form, aOutput.
1.347 + *
1.348 + * aOutput must have CPBDecryptorSet::MaxOutputLength() empty bytes
1.349 + * remaining in its length.
1.350 + *
1.351 + * @param aInput The ciphertext.
1.352 + * @param aOutput The plaintext.
1.353 + */
1.354 + void Process(const TDesC8& aInput, TDes8& aOutput);
1.355 +
1.356 + /**
1.357 + * Transforms aInput into its decrypted form, aOutput, and applies a
1.358 + * padding scheme to ensure a block aligned result.
1.359 + *
1.360 + * aOutput must have CPBDecryptorSet::MaxFinalOutputLength()
1.361 + * empty bytes remaining in its length.
1.362 + *
1.363 + * @param aInput The ciphertext.
1.364 + * @param aOutput The plaintext.
1.365 + */
1.366 + void ProcessFinalL(const TDesC8& aInput, TDes8& aOutput);
1.367 +
1.368 + /**
1.369 + * Gets the maximum size of the output given a certain input length.
1.370 + *
1.371 + * @param aMaxInputLength The maximum input length in bytes.
1.372 + * @return The maximum output length in bytes.
1.373 + */
1.374 + TInt MaxOutputLength(TUint aMaxInputLength) const;
1.375 +
1.376 + /**
1.377 + * Gets the maximum size of the output given a certain input length.
1.378 + *
1.379 + * @param aMaxInputLength The maximum input length in bytes.
1.380 + * @return The maximum output length in bytes.
1.381 + */
1.382 + TInt MaxFinalOutputLength(TUint aMaxInputLength) const;
1.383 +
1.384 + /** Destructor */
1.385 + virtual ~CPBDecryptorSet();
1.386 +protected:
1.387 + /* @internalComponent */
1.388 + CPBDecryptorSet();
1.389 + /* @internalComponent */
1.390 + void ConstructL(TPBECipher aCipher, const TDesC8& aKey, const TDesC8& aIV);
1.391 +private:
1.392 + TPtrC8 ProcessIV(const TDesC8& aInput);
1.393 +private:
1.394 + CSymmetricCipher* iCipher;
1.395 + HBufC8* iIVBuf;
1.396 + TBool iIVSent;
1.397 + };
1.398 +
1.399 +#endif