Update contrib.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * ** IMPORTANT ** API's in this file are published to 3rd party developers via the
16 * Symbian website. Changes to these API's should be treated as PublishedAll API changes and the Security TA should be consulted.
17 * Asymmetric keys implementation
28 #ifndef __ASYMMETRICKEYS_H__
29 #define __ASYMMETRICKEYS_H__
36 * Defines the various ways of representing supported RSA private keys.
39 enum TRSAPrivateKeyType
42 * Standard type of RSA private key
44 * This consists of the modulus (n) and decryption exponent (d).
48 * CRT (Chinese Remainder Theorem) type of RSA private key
50 * This consists of the the first factor (p), the second factor (q),
51 * the first factor's CRT exponent (dP), the second factor's CRT exponent (dQ),
52 * and the (first) CRT coefficient (qInv). The two factors, p and q, are the
53 * first two prime factors of the RSA modulus, n.
56 //We may support types like this in the future (currently these are a patent
58 //EMulti, //multi prime version of EStandard
59 //EMultiCRT //multi prime version of EStandardCRT
63 * Concrete class representing the parameters common to both an RSA public and
66 * See ANSI X9.31 and RSA PKCS#1
69 class CRSAParameters : public CBase
73 * Gets the RSA parameter, n (the modulus)
75 * @return The RSA parameter, n
77 IMPORT_C const TInteger& N(void) const;
80 IMPORT_C virtual ~CRSAParameters(void);
85 * @param aN The RSA parameter, n (the modulus)
87 IMPORT_C CRSAParameters(RInteger& aN);
89 /** Default constructor */
90 IMPORT_C CRSAParameters(void);
92 /** The RSA modulus, n, a positive integer */
95 CRSAParameters(const CRSAParameters&);
96 CRSAParameters& operator=(const CRSAParameters&);
100 * Representation of an RSA public key.
102 * An RSA public key is identified by its modulus (n) and its encryption exponent
106 class CRSAPublicKey : public CRSAParameters
110 * Creates a new CRSAPublicKey object from a specified
111 * modulus and encryption exponent.
113 * @param aN The RSA parameter, n (the modulus)
114 * @param aE The RSA parameter, e (the encryption exponent)
115 * @return A pointer to a new CRSAPublicKey object
117 * @leave KErrArgument If either aN or aE are not positive integers,
118 * and releases ownership.
120 IMPORT_C static CRSAPublicKey* NewL(RInteger& aN, RInteger& aE);
123 * Creates a new CRSAPublicKey object from a specified
124 * modulus and encryption exponent.
126 * The returned pointer is put onto the cleanup stack.
128 * @param aN The RSA parameter, n (the modulus)
129 * @param aE The RSA parameter, e (the encryption exponent)
130 * @return A pointer to a new CRSAPublicKey object
132 * @leave KErrArgument If either aN or aE are not positive integers,
133 * and releases ownership.
135 IMPORT_C static CRSAPublicKey* NewLC(RInteger& aN, RInteger& aE);
138 * Gets the RSA parameter, e (the encryption exponent)
140 * @return The RSA parameter, e
142 IMPORT_C const TInteger& E(void) const;
145 IMPORT_C virtual ~CRSAPublicKey(void);
150 * @param aN The RSA parameter, n (the modulus)
151 * @param aE The RSA parameter, e (the encryption exponent)
153 IMPORT_C CRSAPublicKey(RInteger& aN, RInteger& aE);
155 /** Default constructor */
156 IMPORT_C CRSAPublicKey(void);
158 /** The RSA encryption exponent, e */
161 CRSAPublicKey(const CRSAPublicKey&);
162 CRSAPublicKey& operator=(const CRSAPublicKey&);
167 * Non-exported container class for the various ways of representing an RSA
170 * To instantiate a representation of an RSA private key, find a
171 * subclass of this appropriate to your key type.
174 class CRSAPrivateKey : public CRSAParameters
180 * @param aKeyType The type of the RSA private key
181 * @param aN The RSA parameter, n (the modulus)
184 CRSAPrivateKey(const TRSAPrivateKeyType aKeyType, RInteger& aN);
187 * Gets the type of RSA private key
189 * @return The RSA private key type
191 inline const TRSAPrivateKeyType PrivateKeyType() const {return (iKeyType);};
193 /** The type of the RSA private key */
194 const TRSAPrivateKeyType iKeyType;
196 CRSAPrivateKey(const CRSAPrivateKey&);
197 CRSAPrivateKey& operator=(const CRSAPrivateKey&);
201 * The 'classical' representation of a RSA private key.
203 * Such a private key is composed of a modulus (n) and a decryption exponent (d).
206 class CRSAPrivateKeyStandard : public CRSAPrivateKey
210 * Creates a new CRSAPrivateKeyStandard object from a specified
211 * modulus and decryption exponent.
213 * @param aN The RSA parameter, n (the modulus)
214 * @param aD The RSA parameter, d (the decryption exponent)
215 * @return A pointer to a new CRSAPrivateKeyStandard object
217 * @leave KErrArgument If either aN or aD are not positive integers,
218 * and releases ownership.
220 IMPORT_C static CRSAPrivateKeyStandard* NewL(RInteger& aN, RInteger& aD);
223 * Creates a new CRSAPrivateKeyStandard object from a specified
224 * modulus and decryption exponent.
226 * The returned pointer is put onto the cleanup stack.
228 * @param aN The RSA parameter, n (the modulus)
229 * @param aD The RSA parameter, d (the decryption exponent)
230 * @return A pointer to a new CRSAPrivateKeyStandard object
232 * @leave KErrArgument If either aN or aD are not positive integers,
233 * and releases ownership.
235 IMPORT_C static CRSAPrivateKeyStandard* NewLC(RInteger& aN, RInteger& aD);
238 * Gets the RSA parameter, d (the decryption exponent)
240 * @return The RSA parameter, d
242 IMPORT_C const TInteger& D(void) const;
245 IMPORT_C virtual ~CRSAPrivateKeyStandard(void);
250 * @param aN The RSA parameter, n (the modulus)
251 * @param aD The RSA parameter, d (the decryption exponent)
253 IMPORT_C CRSAPrivateKeyStandard(RInteger& aN, RInteger& aD);
255 /** The RSA decryption exponent, d */
258 CRSAPrivateKeyStandard(const CRSAPrivateKeyStandard&);
259 CRSAPrivateKeyStandard& operator=(const CRSAPrivateKeyStandard&);
264 * An alternate representation of an RSA private key providing significant
265 * speed enhancements through its use of the Chinese Remainder Theorem (CRT).
267 * Here, a private key is represented by a modulus (n), the two prime factors of
268 * the modulus (p, q), p's CRT exponent (dP), q's CRT exponent (dQ), and the CRT
269 * coefficient (qInv). See PKCS#1 at http://www.rsasecurity.com/rsalabs/pkcs/
270 * for more information.
273 class CRSAPrivateKeyCRT : public CRSAPrivateKey
277 * Creates a new CRSAPrivateKeyCRT object from a specified
278 * modulus and decryption exponent.
280 * @param iN The RSA parameter, n (the modulus)
281 * @param aP The RSA parameter, p (the first factor)
282 * @param aQ The RSA parameter, q (the second factor)
283 * @param aDP The RSA parameter, dP (the first factor's CRT exponent)
284 * @param aDQ The RSA parameter, dQ (the second factor's CRT exponent)
285 * @param aQInv The RSA parameter, qInv (the CRT coefficient)
286 * @return A pointer to a new CRSAPrivateKeyCRT object
288 * @leave KErrArgument If any of the parameters are not positive integers,
289 * and releases ownership.
291 IMPORT_C static CRSAPrivateKeyCRT* NewL(RInteger& iN, RInteger& aP,
292 RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv);
295 * Creates a new CRSAPrivateKeyCRT object from a specified
296 * modulus and decryption exponent.
298 * The returned pointer is put onto the cleanup stack.
300 * @param iN The RSA parameter, n (the modulus)
301 * @param aP The RSA parameter, p (the first factor)
302 * @param aQ The RSA parameter, q (the second factor)
303 * @param aDP The RSA parameter, dP (the first factor's CRT exponent)
304 * @param aDQ The RSA parameter, dQ (the second factor's CRT exponent)
305 * @param aQInv The RSA parameter, qInv (the CRT coefficient)
306 * @return A pointer to a new CRSAPrivateKeyCRT object
308 * @leave KErrArgument If any of the parameters are not positive integers,
309 * and releases ownership.
311 IMPORT_C static CRSAPrivateKeyCRT* NewLC(RInteger& iN, RInteger& aP,
312 RInteger& aQ, RInteger& aDP, RInteger& aDQ, RInteger& aQInv);
315 IMPORT_C virtual ~CRSAPrivateKeyCRT(void);
318 * Gets the RSA parameter, p (the first factor)
320 * @return The first factor
322 IMPORT_C const TInteger& P(void) const;
325 * Gets the RSA parameter, q (the second factor)
327 * @return The second factor
329 IMPORT_C const TInteger& Q(void) const;
332 * Gets the RSA parameter, dP (the first factor's CRT exponent)
334 * @return The first factor's CRT exponent
336 IMPORT_C const TInteger& DP(void) const;
339 * Gets the RSA parameter, dQ (the second factor's CRT exponent)
341 * @return The second factor's CRT exponent
343 IMPORT_C const TInteger& DQ(void) const;
346 * Gets the RSA parameter, qInv (the CRT coefficient)
348 * @return The CRT coefficient
350 IMPORT_C const TInteger& QInv(void) const;
355 * @param aN The RSA parameter, n (the modulus)
356 * @param aP The RSA parameter, p (the first factor)
357 * @param aQ The RSA parameter, q (the second factor)
358 * @param aDP The RSA parameter, dP (the first factor's CRT exponent)
359 * @param aDQ The RSA parameter, dQ (the second factor's CRT exponent)
360 * @param aQInv The RSA parameter, qInv (the CRT coefficient)
362 IMPORT_C CRSAPrivateKeyCRT(RInteger& aN, RInteger& aP, RInteger& aQ,
363 RInteger& aDP, RInteger& aDQ, RInteger& aQInv);
365 /** The RSA parameter, p, which is the first factor */
367 /** The RSA parameter, q, which is the second factor */
369 /** The RSA parameter, dP, which is the first factor's CRT exponent */
371 /** The RSA parameter, dQ, which is the second factor's CRT exponent */
373 /** The RSA parameter, qInv, which is the CRT coefficient */
376 CRSAPrivateKeyCRT(const CRSAPrivateKeyCRT&);
377 CRSAPrivateKeyCRT& operator=(const CRSAPrivateKeyCRT&);
382 * This class is capable of generating an RSA public/private key pair.
384 * By default, it generates 2 prime (standard) CRT private keys.
387 class CRSAKeyPair : public CBase
391 * Creates a new RSA key pair
393 * @param aModulusBits The length of the modulus, n (in bits)
394 * @param aKeyType The type of the RSA key
395 * @return A pointer to a new CRSAKeyPair object
397 * @leave KErrNotSupported If the type of RSA key is not supported
399 IMPORT_C static CRSAKeyPair* NewL(TUint aModulusBits,
400 TRSAPrivateKeyType aKeyType = EStandardCRT);
403 * Creates a new RSA key pair
405 * The returned pointer is put onto the cleanup stack.
407 * @param aModulusBits The length of the modulus, n (in bits)
408 * @param aKeyType The type of the RSA key
409 * @return A pointer to a new CRSAKeyPair object
411 * @leave KErrNotSupported If the type of RSA key is not supported
413 IMPORT_C static CRSAKeyPair* NewLC(TUint aModulusBits,
414 TRSAPrivateKeyType aKeyType = EStandardCRT);
417 * Gets the RSA public key
419 * @return A CRSAPublicKey object
421 IMPORT_C const CRSAPublicKey& PublicKey(void) const;
424 * Gets the RSA private key
426 * @return A CRSAPrivateKey object
428 IMPORT_C const CRSAPrivateKey& PrivateKey(void) const;
430 /** The destructor frees all resources owned by the object, prior to its destruction. */
431 IMPORT_C virtual ~CRSAKeyPair(void);
433 /** Default destructor */
434 IMPORT_C CRSAKeyPair(void);
436 /** The RSA public key */
437 CRSAPublicKey* iPublic;
438 /** The RSA private key */
439 CRSAPrivateKey* iPrivate;
441 void ConstructL(TUint aModulusBits, TRSAPrivateKeyType aKeyType,
442 TUint aPublicExponent);
443 CRSAKeyPair(const CRSAKeyPair&);
444 CRSAKeyPair& operator=(const CRSAKeyPair&);
448 * Representation of the parameters used to generate the primes in a
449 * CDSAParameters object.
451 * Given such a certificate, one can ensure that the DSA
452 * primes contained in CDSAParameters were generated correctly.
454 * @see CDSAParameters::ValidatePrimesL()
457 class CDSAPrimeCertificate : public CBase
461 * Creates a new DSA prime certificate from a specified
462 * seed and counter value.
464 * @param aSeed The seed from a DSA key generation process
465 * @param aCounter The counter value from a DSA key generation process
466 * @return A pointer to a new CDSAPrimeCertificate object
468 IMPORT_C static CDSAPrimeCertificate* NewL(const TDesC8& aSeed,
472 * Creates a new DSA prime certificate from a specified
473 * seed and counter value.
475 * The returned pointer is put onto the cleanup stack.
477 * @param aSeed The seed from a DSA key generation process
478 * @param aCounter The counter value from a DSA key generation process
479 * @return A pointer to a new CDSAPrimeCertificate object
481 IMPORT_C static CDSAPrimeCertificate* NewLC(const TDesC8& aSeed,
485 * Gets the seed of the DSA prime certificate
489 IMPORT_C const TDesC8& Seed(void) const;
492 * Gets the counter value of the DSA prime certificate
494 * @return The counter's value
496 IMPORT_C TUint Counter(void) const;
499 IMPORT_C virtual ~CDSAPrimeCertificate(void);
504 * @param aCounter The DSA key generation counter
506 IMPORT_C CDSAPrimeCertificate(TUint aCounter);
508 /** Default constructor */
509 IMPORT_C CDSAPrimeCertificate(void);
511 void ConstructL(const TDesC8& aSeed);
513 /** The DSA key generation seed */
515 /** The DSA key generation counter */
518 CDSAPrimeCertificate(const CDSAPrimeCertificate&);
519 CDSAPrimeCertificate& operator=(const CDSAPrimeCertificate&);
523 * Concrete class representing the parameters common to both a DSA public and
526 * See FIPS 186-2, Digital Signature Standard
529 class CDSAParameters : public CBase
533 * Gets the DSA parameter, p (the prime)
535 * @return The DSA parameter, p
537 IMPORT_C const TInteger& P(void) const;
540 * Gets the DSA parameter, q (the subprime)
542 * @return The DSA parameter, q
544 IMPORT_C const TInteger& Q(void) const;
547 * Gets the DSA parameter, g (the base)
549 * @return The DSA parameter, g
551 IMPORT_C const TInteger& G(void) const;
554 * Validates the primes regenerated from a DSA prime certificate
556 * @param aCert The DSA prime certificate that contains the seed and
557 * counter value from a DSA key generation process
558 * @return Whether or not the primes are valid
560 IMPORT_C TBool ValidatePrimesL(const CDSAPrimeCertificate& aCert) const;
563 * Whether or not the prime is of a valid length
565 * It is valid if the length of the prime modulus is between KMinPrimeLength
566 * and KMaxPrimeLength bits, and the prime is a multiple of KPrimeLengthMultiple.
568 * @param aPrimeBits The prime modulus
569 * @return ETrue, if within the constraints; EFalse, otherwise.
571 IMPORT_C static TBool ValidPrimeLength(TUint aPrimeBits);
574 IMPORT_C virtual ~CDSAParameters(void);
577 * Creates a new DSA parameters object from a specified
578 * prime, subprime, and base.
580 * @param aP The DSA parameter, p (the prime)
581 * @param aQ The DSA parameter, g (the subprime)
582 * @param aG The DSA parameter, g (the base)
583 * @return A pointer to a new CDSAParameters object
585 IMPORT_C static CDSAParameters* NewL(RInteger& aP, RInteger& aQ,
589 static TBool GeneratePrimesL(const TDesC8& aSeed, TUint& aCounter,
590 RInteger& aP, TUint aL, RInteger& aQ, TBool aUseInputCounter=EFalse);
595 * @param aP The DSA parameter, p (the prime)
596 * @param aQ The DSA parameter, g (the subprime)
597 * @param aG The DSA parameter, g (the base)
599 IMPORT_C CDSAParameters(RInteger& aP, RInteger& aQ, RInteger& aG);
601 /** Default constructor */
602 IMPORT_C CDSAParameters(void);
605 * The DSA parameter, p (the prime).
607 * A prime modulus whose length is between KMinPrimeLength and KMaxPrimeLength bits,
608 * and is a multiple of KPrimeLengthMultiple.
613 * The DSA parameter, q (the subprime)
615 * This is a 160-bit prime divisor of <code>p-1</code>.
620 * The DSA parameter, g (the base)
622 * <code>g = h^((p-1)/q) mod p</code>,
624 * where h is any integer less than <code>p-1</code> such that <code>g > 1</code>
628 CDSAParameters(const CDSAParameters&);
629 CDSAParameters& operator=(const CDSAParameters&);
633 * Representation of a DSA public key.
636 class CDSAPublicKey : public CDSAParameters
640 * Creates a new DSA public key object from a specified
641 * primes, base, and public key.
643 * @param aP The DSA parameter, p (the prime)
644 * @param aQ The DSA parameter, q (the subprime)
645 * @param aG The DSA parameter, g (the base)
646 * @param aY The DSA parameter, y (the public key)
647 * @return A pointer to a new CDSAPublicKey object
649 IMPORT_C static CDSAPublicKey* NewL(RInteger& aP, RInteger& aQ,
650 RInteger& aG, RInteger& aY);
653 * Creates a new DSA public key object from a specified
654 * primes, base, and public key.
656 * The returned pointer is put onto the cleanup stack.
658 * @param aP The DSA parameter, p (the prime)
659 * @param aQ The DSA parameter, q (the subprime)
660 * @param aG The DSA parameter, g (the base)
661 * @param aY The DSA parameter, y (the public key)
662 * @return A pointer to a new CDSAPublicKey object
664 IMPORT_C static CDSAPublicKey* NewLC(RInteger& aP, RInteger& aQ,
665 RInteger& aG, RInteger& aY);
668 * Gets the DSA parameter, y (the public key)
670 * @return The DSA parameter, y
672 IMPORT_C const TInteger& Y(void) const;
675 IMPORT_C virtual ~CDSAPublicKey(void);
680 * @param aP The DSA parameter, p (the prime)
681 * @param aQ The DSA parameter, q (the subprime)
682 * @param aG The DSA parameter, g (the base)
683 * @param aY The DSA parameter, y (the public key)
685 IMPORT_C CDSAPublicKey(RInteger& aP, RInteger& aQ, RInteger& aG,
688 /** Default constructor */
689 IMPORT_C CDSAPublicKey(void);
692 * The DSA parameter, y, which is the public key
694 * <code>y = g^x mod p</code>
698 CDSAPublicKey(const CDSAPublicKey&);
699 CDSAPublicKey& operator=(const CDSAPublicKey&);
703 * Representation of a DSA private key.
706 class CDSAPrivateKey : public CDSAParameters
710 * Creates a new DSA private key object from a specified
711 * primes, base, and private key.
713 * @param aP The DSA parameter, p (the prime)
714 * @param aQ The DSA parameter, q (the subprime)
715 * @param aG The DSA parameter, g (the base)
716 * @param aX The DSA parameter, x (the private key)
717 * @return A pointer to a new CDSAPrivateKey object
719 IMPORT_C static CDSAPrivateKey* NewL(RInteger& aP, RInteger& aQ,
720 RInteger& aG, RInteger& aX);
723 * Creates a new DSA private key object from a specified
724 * primes, base, and private key.
726 * The returned pointer is put onto the cleanup stack.
728 * @param aP The DSA parameter, p (the prime)
729 * @param aQ The DSA parameter, q (the subprime)
730 * @param aG The DSA parameter, g (the base)
731 * @param aX The DSA parameter, x (the private key)
732 * @return A pointer to a new CDSAPrivateKey object
734 IMPORT_C static CDSAPrivateKey* NewLC(RInteger& aP, RInteger& aQ,
735 RInteger& aG, RInteger& aX);
738 * Gets the DSA parameter, x (the private key)
740 * @return The DSA parameter, x
742 IMPORT_C const TInteger& X(void) const;
745 IMPORT_C virtual ~CDSAPrivateKey(void);
750 * @param aP The DSA parameter, p (the prime)
751 * @param aQ The DSA parameter, q (the subprime)
752 * @param aG The DSA parameter, g (the base)
753 * @param aX The DSA parameter, x (the private key)
755 IMPORT_C CDSAPrivateKey(RInteger& aP, RInteger& aQ, RInteger& aG,
758 /** Default constructor */
759 IMPORT_C CDSAPrivateKey(void);
762 * The DSA parameter, x, which is the private key
764 * A pseudorandomly generated integer whose value is between 0 and q.
768 CDSAPrivateKey(const CDSAPrivateKey&);
769 CDSAPrivateKey& operator=(const CDSAPrivateKey&);
773 * This class is capable of generating a DSA public/private key pair.
776 class CDSAKeyPair : public CBase
780 * Creates a new DSA key pair and also a DSA prime certificate
782 * @param aSize The length (in bits) of the DSA parameter, p (the prime)
783 * @return A pointer to a new CDSAKeyPair object
785 IMPORT_C static CDSAKeyPair* NewL(TUint aSize);
788 * Creates a new DSA key pair and also a DSA prime certificate
790 * The returned pointer is put onto the cleanup stack.
792 * @param aSize The length (in bits) of the DSA parameter, p (the prime)
793 * @return A pointer to a new CDSAKeyPair object
795 IMPORT_C static CDSAKeyPair* NewLC(TUint aSize);
798 * Gets the DSA public key
800 * @return The DSA public key object
802 IMPORT_C const CDSAPublicKey& PublicKey(void) const;
805 * Gets the DSA private key
807 * @return The DSA private key object
809 IMPORT_C const CDSAPrivateKey& PrivateKey(void) const;
812 * Gets the DSA prime certificate (i.e., the seed and counter)
814 * @return The DSA prime certificate object
816 IMPORT_C const CDSAPrimeCertificate& PrimeCertificate(void) const;
818 /** The destructor frees all resources owned by the object, prior to its destruction. */
819 IMPORT_C virtual ~CDSAKeyPair(void);
821 /** Default constructor */
822 IMPORT_C CDSAKeyPair(void);
824 /** The DSA public key */
825 CDSAPublicKey* iPublic;
826 /** The DSA private key */
827 CDSAPrivateKey* iPrivate;
828 /** The DSA prime certificate */
829 CDSAPrimeCertificate* iPrimeCertificate;
831 void ConstructL(TUint aSize);
832 CDSAKeyPair(const CDSAKeyPair&);
833 CDSAKeyPair& operator=(const CDSAKeyPair&);
837 * Concrete class representing the parameters common to both
838 * a Diffie-Hellman (DH) public and private key.
841 class CDHParameters : public CBase
845 * Gets the DH parameter, n
847 * @return An integer representing the DH parameter, n
849 IMPORT_C const TInteger& N(void) const;
852 * Gets the DH parameter, g
854 * @return An integer representing the DH parameter, g
856 IMPORT_C const TInteger& G(void) const;
859 IMPORT_C virtual ~CDHParameters(void);
864 * @param aN The DH parameter, n
865 * @param aG The DH parameter, g
867 IMPORT_C CDHParameters(RInteger& aN, RInteger& aG);
869 /** Default constructor */
870 IMPORT_C CDHParameters(void);
873 * The DH parameter, n (a prime number)
875 * <code>X = g^x mod n</code> (note the case sensitivity)
879 * The DH parameter, g (the generator)
881 * <code>X = g^x mod n</code> (note the case sensitivity)
885 CDHParameters(const CDHParameters&);
886 CDHParameters& operator=(const CDHParameters&);
890 * Representation of a Diffie-Hellman (DH) public key.
893 class CDHPublicKey : public CDHParameters
897 * Creates a new DH public key from a specified
898 * large prime, generator, and random large integer.
900 * @param aN The DH parameter, n (a large prime)
901 * @param aG The DH parameter, g (the generator)
902 * @param aX The DH value, X
903 * @return A pointer to a new CDHPublicKey object
905 IMPORT_C static CDHPublicKey* NewL(RInteger& aN, RInteger& aG,
909 * Creates a new DH public key from a specified
910 * large prime, generator, and random large integer.
912 * The returned pointer is put onto the cleanup stack.
914 * @param aN The DH parameter, n (a large prime)
915 * @param aG The DH parameter, g (the generator)
916 * @param aX The DH value, X
917 * @return A pointer to a new CDHPublicKey object
919 IMPORT_C static CDHPublicKey* NewLC(RInteger& aN, RInteger& aG,
923 * Gets the DH value, X
925 * @return The DH value, X
927 IMPORT_C const TInteger& X(void) const;
930 IMPORT_C virtual ~CDHPublicKey(void);
935 * @param aN The DH parameter, n (a large prime)
936 * @param aG The DH parameter, g (the generator)
937 * @param aX The DH value, X
939 IMPORT_C CDHPublicKey(RInteger& aN, RInteger& aG, RInteger& aX);
942 IMPORT_C CDHPublicKey(void);
947 * <code>X = g^x mod n</code> (note the case sensitivity)
951 CDHPublicKey(const CDHPublicKey&);
952 CDHPublicKey& operator=(const CDHPublicKey&);
956 * Representation of a Diffie-Hellman (DH) private key.
959 class CDHPrivateKey : public CDHParameters
963 * Creates a new DH private key from a specified
964 * large prime, generator, and random large integer.
966 * @param aN The DH parameter, n (a large prime)
967 * @param aG The DH parameter, g (the generator)
968 * @param ax The DH value, x (a random large integer)
969 * @return A pointer to a new CDHPrivateKey object
971 IMPORT_C static CDHPrivateKey* NewL(RInteger& aN, RInteger& aG,
975 * Creates a new DH private key from a specified
976 * large prime, generator, and random large integer.
978 * The returned pointer is put onto the cleanup stack.
980 * @param aN The DH parameter, n (a large prime)
981 * @param aG The DH parameter, g (the generator)
982 * @param ax The DH value, x (a random large integer)
983 * @return A pointer to a new CDHPrivateKey object
985 IMPORT_C static CDHPrivateKey* NewLC(RInteger& aN, RInteger& aG,
989 * Gets the DH value, x, which is a random large integer.
991 * @return The DH value, x
993 IMPORT_C const TInteger& x(void) const;
996 IMPORT_C virtual ~CDHPrivateKey(void);
1001 * @param aN The DH parameter, n (a large prime)
1002 * @param aG The DH parameter, g (the generator)
1003 * @param ax The DH value, x (a random large integer)
1005 IMPORT_C CDHPrivateKey(RInteger& aN, RInteger& aG, RInteger& ax);
1008 IMPORT_C CDHPrivateKey(void);
1011 * The DH value, x, which is a random large integer.
1013 * <code>X = g^x mod n</code> (note the case sensitivity)
1017 CDHPrivateKey(const CDHPrivateKey&);
1018 CDHPrivateKey& operator=(const CDHPrivateKey&);
1022 * This class is capable of generating a Diffie-Hellman (DH) public/private key pair.
1025 class CDHKeyPair : public CBase
1029 * Creates a new DH key pair from a random large integer,
1030 * and a specified large prime and generator.
1032 * @param aN The DH parameter, n (a large prime)
1033 * @param aG The DH parameter, g (the generator)
1034 * @return A pointer to a new CDHKeyPair object
1036 * @leave KErrArgument If aG is out of bounds
1038 IMPORT_C static CDHKeyPair* NewL(RInteger& aN, RInteger& aG);
1041 * Creates a new DH key pair from a random large integer,
1042 * and a specified large prime and generator.
1044 * The returned pointer is put onto the cleanup stack.
1046 * @param aN The DH parameter, n (a large prime)
1047 * @param aG The DH parameter, g (the generator)
1048 * @return A pointer to a new CDHKeyPair object
1050 * @leave KErrArgument If aG is out of bounds
1052 IMPORT_C static CDHKeyPair* NewLC(RInteger& aN, RInteger& aG);
1055 * Creates a new DH key pair from a specified
1056 * large prime, generator, and random large integer.
1058 * @param aN The DH parameter, n (a large prime)
1059 * @param aG The DH parameter, g (the generator)
1060 * @param ax The DH value, x (a random large integer)
1061 * @return A pointer to a new CDHKeyPair object
1063 * @leave KErrArgument If either aG or ax are out of bounds
1065 IMPORT_C static CDHKeyPair* NewL(RInteger& aN, RInteger& aG, RInteger& ax);
1068 * Creates a new DH key pair from a specified
1069 * large prime, generator, and random large integer.
1071 * The returned pointer is put onto the cleanup stack.
1073 * @param aN The DH parameter, n (a large prime)
1074 * @param aG The DH parameter, g (the generator)
1075 * @param ax The DH value, x (a random large integer)
1076 * @return A pointer to a new CDHKeyPair object
1078 * @leave KErrArgument If either aG or ax are out of bounds
1080 IMPORT_C static CDHKeyPair* NewLC(RInteger& aN, RInteger& aG, RInteger& ax);
1083 * Gets the DH public key
1085 * @return The DH public key
1087 IMPORT_C const CDHPublicKey& PublicKey(void) const;
1090 * Gets the DH private key
1092 * @return The DH private key
1094 IMPORT_C const CDHPrivateKey& PrivateKey(void) const;
1096 /** The destructor frees all resources owned by the object, prior to its destruction. */
1097 IMPORT_C virtual ~CDHKeyPair(void);
1099 /** Default constructor */
1100 IMPORT_C CDHKeyPair(void);
1105 * @param aN The DH parameter, n (a large prime)
1106 * @param aG The DH parameter, g (the generator)
1108 IMPORT_C void ConstructL(RInteger& aN, RInteger& aG);
1113 * @param aN The DH parameter, n (a large prime)
1114 * @param aG The DH parameter, g (the generator)
1115 * @param ax The DH value, x (a random large integer)
1117 IMPORT_C void ConstructL(RInteger& aN, RInteger& aG, RInteger& ax);
1120 /** The DH public key */
1121 CDHPublicKey* iPublic;
1122 /** The DH private key */
1123 CDHPrivateKey* iPrivate;
1125 CDHKeyPair(const CDHKeyPair&);
1126 CDHKeyPair& operator=(const CDHKeyPair&);
1128 #endif // __ASYMMETRICKEYS_H__