crypto/weakcryptospi/inc/spi/macplugin.h
changeset 8 35751d3474b7
child 33 cf642210ecb7
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * MAC(message authentication code) plugin interface
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22  @publishedPartner
       
    23  @released
       
    24 */
       
    25 
       
    26 #ifndef __MAC_PLUGIN_H
       
    27 #define __MAC_PLUGIN_H
       
    28 
       
    29 #include <cryptospi/cryptoplugin.h>
       
    30 
       
    31 namespace CryptoSpi
       
    32 	{
       
    33 	class CKey;
       
    34 	
       
    35 	/**
       
    36 	 * The generic CryptoSPI MAC definition. This allow plug-ins
       
    37 	 * to implement extensible MAC functionality and to work with all
       
    38 	 * known existing hash based or symmetric cipher based MAC algorithms
       
    39 	 * for e.g. MD2, MD4, MD5, SHA-1, SHA-256, SHA-512, RIPEMD-160, etc. or 
       
    40 	 * AES-XCBC-MAC-96, AES-XCBC-PRF-128 etc. respectively. 
       
    41 	 */
       
    42 	class MMac : public MPlugin
       
    43 	    {
       
    44 	public:
       
    45 
       
    46 		/**
       
    47 		 * Adds message to the internal representation of data for which the MAC value
       
    48 		 * needs to be evaluated and then returns a TPtrC8 of the finalised MAC value 
       
    49 		 * of all the previously appended messages. 
       
    50 		 * 
       
    51 		 * @param aMessage  The data for which MAC value is to be evaluated.
       
    52 		 * @return          A descriptor pointer to the buffer containing the
       
    53 		 *                  resulting MAC value.
       
    54 		 */
       
    55 		virtual TPtrC8 MacL(const TDesC8& aMessage) = 0;    
       
    56 		
       
    57         /**
       
    58          * Adds data to the internal representation of messages for which the MAC value
       
    59 		 * needs to be evaluated.
       
    60          * 
       
    61          * @param aMessage	The data to be included in the MAC evaluation.
       
    62          */
       
    63         virtual void UpdateL(const TDesC8& aMessage) = 0;
       
    64 
       
    65         /**
       
    66          * Produces a final MAC value from all the previous updates of data to be MACed. 
       
    67          * It resets the MAC algorithm in a state similar to creating a new MAC instance
       
    68          * with the same underlying algorithm and supplied symmetric key.
       
    69          *  
       
    70          * @param aMessage	The data to be included in the MAC evaluation.
       
    71 		 * @return          A descriptor pointer to the buffer containing the
       
    72 		 *                  resulting MAC value.
       
    73 		 */
       
    74         virtual TPtrC8 FinalL(const TDesC8& aMessage) = 0;
       
    75 
       
    76 		/**
       
    77 		 * This re-initialises the underlying MAC algorithm with a new symmetric key. 
       
    78          * It resets the MAC algorithm in a state similar to creating a new MAC instance
       
    79          * with the same underlying algorithm but a new symmetric key.
       
    80 		 *
       
    81 		 * @param aKey  Symmetric key for calculating message authentication code value. 
       
    82 		 */
       
    83 		virtual void ReInitialiseAndSetKeyL(const CKey& aKey) = 0;
       
    84 		
       
    85 		/**
       
    86 		 * Creates a brand new reset MMac object containing no state
       
    87 		 * information from the current object.  
       
    88 		 * 
       
    89 		 * @return 	A pointer to the new reset MMac object
       
    90 		 */
       
    91 		virtual MMac* ReplicateL() = 0;		
       
    92 
       
    93 		/** 
       
    94 		 * Creates a new MMac object with the exact same state as
       
    95 		 * the current object.  
       
    96  		 * This function copies all internal state of the message digest.
       
    97 		 * 
       
    98 		 * @return 	A pointer to the new MMac object
       
    99 		 */
       
   100 		virtual MMac* CopyL() = 0;
       
   101 	    };
       
   102 
       
   103 	/**
       
   104 	 * Asynchronous MAC interface typically used by the plug-in implementations 
       
   105 	 * that are based for dedicated crypto hardware.
       
   106 	 */    
       
   107 	class MAsyncMac : public MPlugin
       
   108 	    {
       
   109 	public:
       
   110 
       
   111 		/**
       
   112 		 * Adds message to the internal representation of data for which the MAC value,
       
   113 		 * needs to be evaluated and then returns a TPtrC8 of the finalised MAC value 
       
   114 		 * of all the previously appended messages. 
       
   115 		 * 
       
   116 		 * @param aMessage  The data for which MAC value is to be evaluated.
       
   117 		 * @param aStatus   Holds the completion status of an asynchronous 
       
   118 		 * 					request for MAC evaluation.
       
   119 		 * @return          A descriptor pointer to the buffer containing the
       
   120 		 *                  resulting MAC value.
       
   121 		 */
       
   122 		virtual TPtrC8 MacL(const TDesC8& aMessage, TRequestStatus& aStatus) = 0;    
       
   123 			
       
   124         /**
       
   125          * Adds data to the internal representation of messages for which the MAC value
       
   126 		 * needs to be evaluated.
       
   127          *
       
   128          * @param aMessage	The data to be included in the MAC evaluation.
       
   129 		 * @param aStatus   Holds the completion status of an asynchronous 
       
   130 		 * 					request for MAC evaluation.
       
   131          */
       
   132         virtual void UpdateL(const TDesC8& aMessage, TRequestStatus& aStatus) = 0;
       
   133 
       
   134         /**
       
   135          * Produces a final MAC value from all the previous updates of data to be MACed. 
       
   136          * It resets the MAC algorithm in a state similar to creating a new MAC instance
       
   137          * with the same underlying algorithm and supplied symmetric key.
       
   138          *  
       
   139          * @param aMessage	The data to be included in the MAC evaluation.
       
   140 		 * @param aStatus   Holds the completion status of an asynchronous 
       
   141 		 * 					request for MAC evaluation.
       
   142 		 * @return          A descriptor pointer to the buffer containing the
       
   143 		 *                  resulting MAC value.
       
   144          */
       
   145         virtual TPtrC8 FinalL(const TDesC8& aMessage, TRequestStatus& aStatus) = 0;
       
   146 
       
   147 	    /**
       
   148 		 * This re-initialises the underlying MAC algorithm with a new symmetric key. 
       
   149          * It resets the MAC algorithm in a state similar to creating a new MAC instance
       
   150          * with the same underlying algorithm but a new symmetric key.
       
   151 		 *
       
   152 		 * @param aKey     Symmetric key for calculating message authentication code value. 
       
   153 		 * @param aStatus  Holds the completion status of an asynchronous 
       
   154 		 * 				   request for MAC evaluation.
       
   155 		 */
       
   156 		virtual void ReInitialiseAndSetKeyL(const CKey& aKey) = 0;    
       
   157 		
       
   158 		/**
       
   159 		 * Cancels an outstanding request from the client.
       
   160 		 */
       
   161 		virtual void Cancel() = 0;
       
   162 		
       
   163 		/**
       
   164 		 * Creates a brand new reset MAsyncMac object containing no state
       
   165 		 * information from the current object.  
       
   166 		 * 
       
   167 		 * @return	A pointer to the new reset MAsyncHash object
       
   168 		 */
       
   169 		virtual MAsyncMac* ReplicateL() = 0;		
       
   170 
       
   171 		/** 
       
   172 		 * Creates a new MAsyncMac object with the exact same state as
       
   173 		 * the current object.  
       
   174 		 * This function copies all internal state of the message digest.
       
   175 		 * 
       
   176 		 * @return	A pointer to the new MAsyncMac object
       
   177 		 */
       
   178 		virtual MAsyncMac* CopyL() = 0;
       
   179 	    };
       
   180 	}
       
   181 
       
   182 #endif  __MAC_PLUGIN_H