|         |      1 /**  | 
|         |      2  * XMLSec library | 
|         |      3  * | 
|         |      4  * This is free software; see Copyright file in the source | 
|         |      5  * distribution for preciese wording. | 
|         |      6  *  | 
|         |      7  * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> | 
|         |      8  * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.  | 
|         |      9  */ | 
|         |     10 #include "xmlsecc_config.h" | 
|         |     11 #ifndef XMLSEC_NO_HMAC | 
|         |     12 #include "xmlsecc_globals.h" | 
|         |     13  | 
|         |     14 #include <string.h> | 
|         |     15  | 
|         |     16 #include <libxml2_globals.h> | 
|         |     17 #include <e32err.h>         //definition of KErrNoMemory | 
|         |     18  | 
|         |     19 #include "xmlsec_xmlsec.h" | 
|         |     20 #include "xmlsec_xmltree.h" | 
|         |     21 #include "xmlsec_keys.h" | 
|         |     22 #include "xmlsec_transforms.h" | 
|         |     23 #include "xmlsec_errors.h" | 
|         |     24 #include "xmlsec_error_flag.h" | 
|         |     25  | 
|         |     26 #include "xmlsecc_app.h" | 
|         |     27 #include "xmlsecc_crypto.h" | 
|         |     28 #include "xmlsecc_cryptowrapper.h" | 
|         |     29  | 
|         |     30 #define XMLSEC_SYMBIANCRYPTO_MAX_HMAC_SIZE		128 | 
|         |     31  | 
|         |     32 /************************************************************************** | 
|         |     33  * | 
|         |     34  * Internal SYMBIANCRYPTO HMAC CTX | 
|         |     35  * | 
|         |     36  *****************************************************************************/ | 
|         |     37 typedef struct _xmlSecSymbianCryptoHmacCtx  | 
|         |     38                                       xmlSecSymbianCryptoHmacCtx, *xmlSecSymbianCryptoHmacCtxPtr; | 
|         |     39 struct _xmlSecSymbianCryptoHmacCtx { | 
|         |     40     int			digest; | 
|         |     41     ScMDHd		digestCtx; | 
|         |     42     xmlSecByte	 	dgst[XMLSEC_SYMBIANCRYPTO_MAX_HMAC_SIZE]; | 
|         |     43     xmlSecSize		dgstSize;	/* dgst size in bits */ | 
|         |     44 };	     | 
|         |     45  | 
|         |     46 xmlSecTransformGetDataTypeMethod const xmlSecCrpytoGetDataTypeMethod  = xmlSecTransformDefaultGetDataType; | 
|         |     47 xmlSecTransformPushBinMethod const xmlSecCryptoPushBinMethod = xmlSecTransformDefaultPushBin; | 
|         |     48 xmlSecTransformPopBinMethod const xmlSecCryptoPopBinMethod = xmlSecTransformDefaultPopBin; | 
|         |     49  | 
|         |     50 /****************************************************************************** | 
|         |     51  * | 
|         |     52  * HMAC transforms | 
|         |     53  * | 
|         |     54  * xmlSecSymbianCryptoHmacCtx is located after xmlSecTransform | 
|         |     55  * | 
|         |     56  *****************************************************************************/ | 
|         |     57 #define xmlSecSymbianCryptoHmacGetCtx(transform) \ | 
|         |     58     ((xmlSecSymbianCryptoHmacCtxPtr)(((xmlSecByte*)(transform)) + sizeof(xmlSecTransform))) | 
|         |     59 #define xmlSecSymbianCryptoHmacSize	\ | 
|         |     60     (sizeof(xmlSecTransform) + sizeof(xmlSecSymbianCryptoHmacCtx)) | 
|         |     61 #define xmlSecSymbianCryptoHmacCheckId(transform) \ | 
|         |     62     (xmlSecTransformCheckId((transform), xmlSecSymbianCryptoTransformHmacSha1Id) || \ | 
|         |     63      xmlSecTransformCheckId((transform), xmlSecSymbianCryptoTransformHmacMd5Id) || \ | 
|         |     64      xmlSecTransformCheckId((transform), xmlSecSymbianCryptoTransformHmacRipemd160Id)) | 
|         |     65  | 
|         |     66 static int 	xmlSecSymbianCryptoHmacInitialize		(xmlSecTransformPtr transform); | 
|         |     67 static void 	xmlSecSymbianCryptoHmacFinalize		(xmlSecTransformPtr transform); | 
|         |     68 static int 	xmlSecSymbianCryptoHmacNodeRead		(xmlSecTransformPtr transform, | 
|         |     69 							 xmlNodePtr node, | 
|         |     70 							 xmlSecTransformCtxPtr transformCtx); | 
|         |     71 static int  	xmlSecSymbianCryptoHmacSetKeyReq		(xmlSecTransformPtr transform,  | 
|         |     72 							 xmlSecKeyReqPtr keyReq); | 
|         |     73 static int  	xmlSecSymbianCryptoHmacSetKey			(xmlSecTransformPtr transform,  | 
|         |     74 							 xmlSecKeyPtr key); | 
|         |     75 static int	xmlSecSymbianCryptoHmacVerify			(xmlSecTransformPtr transform,  | 
|         |     76 							 const xmlSecByte* data,  | 
|         |     77 							 xmlSecSize dataSize, | 
|         |     78 							 xmlSecTransformCtxPtr transformCtx); | 
|         |     79 static int 	xmlSecSymbianCryptoHmacExecute			(xmlSecTransformPtr transform,  | 
|         |     80 							 int last,  | 
|         |     81 							 xmlSecTransformCtxPtr transformCtx); | 
|         |     82  | 
|         |     83 static int  | 
|         |     84 xmlSecSymbianCryptoHmacInitialize(xmlSecTransformPtr transform) { | 
|         |     85     xmlSecSymbianCryptoHmacCtxPtr ctx; | 
|         |     86 #ifndef XMLSEC_GNUTLS_OLD | 
|         |     87     //gpg_err_code_t ret; | 
|         |     88 #endif /* XMLSEC_GNUTLS_OLD */ | 
|         |     89 	int ret; | 
|         |     90  | 
|         |     91     xmlSecAssert2(xmlSecSymbianCryptoHmacCheckId(transform), -1); | 
|         |     92     xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecSymbianCryptoHmacSize), -1); | 
|         |     93  | 
|         |     94     ctx = xmlSecSymbianCryptoHmacGetCtx(transform); | 
|         |     95     xmlSecAssert2(ctx, -1); | 
|         |     96      | 
|         |     97     memset(ctx, 0, sizeof(xmlSecSymbianCryptoHmacCtx)); | 
|         |     98     if(xmlSecTransformCheckId(transform, xmlSecSymbianCryptoTransformHmacSha1Id)) { | 
|         |     99         ctx->digest = SC_MD_SHA1; | 
|         |    100     } else if(xmlSecTransformCheckId(transform, xmlSecSymbianCryptoTransformHmacMd5Id)) { | 
|         |    101         ctx->digest = SC_MD_MD5; | 
|         |    102     } else if(xmlSecTransformCheckId(transform, xmlSecSymbianCryptoTransformHmacRipemd160Id)) { | 
|         |    103         ctx->digest = SC_MD_RMD160; | 
|         |    104     } else { | 
|         |    105 	xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    106 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    107 		    NULL, | 
|         |    108 		    XMLSEC_ERRORS_R_INVALID_TRANSFORM, | 
|         |    109 		    XMLSEC_ERRORS_NO_MESSAGE); | 
|         |    110 	return(-1); | 
|         |    111     } | 
|         |    112      | 
|         |    113     ret = sc_md_open(&ctx->digestCtx, ctx->digest, SC_MD_FLAG_HMAC | SC_MD_FLAG_SECURE); /* we are paranoid */ | 
|         |    114     if(ret != 0 /*GPG_ERR_NO_ERROR*/) { | 
|         |    115         if ( ret != KErrNone ) | 
|         |    116             { | 
|         |    117             xmlSecSetErrorFlag( ret ); | 
|         |    118             } | 
|         |    119 		xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    120 			    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    121 			    "gcry_md_open", | 
|         |    122 			    XMLSEC_ERRORS_R_CRYPTO_FAILED, | 
|         |    123 			    XMLSEC_ERRORS_NO_MESSAGE); | 
|         |    124 		return(-1); | 
|         |    125     } | 
|         |    126      | 
|         |    127     return(0); | 
|         |    128 } | 
|         |    129  | 
|         |    130 static void  | 
|         |    131 xmlSecSymbianCryptoHmacFinalize(xmlSecTransformPtr transform) { | 
|         |    132     xmlSecSymbianCryptoHmacCtxPtr ctx; | 
|         |    133  | 
|         |    134     xmlSecAssert(xmlSecSymbianCryptoHmacCheckId(transform));     | 
|         |    135     xmlSecAssert(xmlSecTransformCheckSize(transform, xmlSecSymbianCryptoHmacSize)); | 
|         |    136  | 
|         |    137     ctx = xmlSecSymbianCryptoHmacGetCtx(transform); | 
|         |    138     xmlSecAssert(ctx); | 
|         |    139  | 
|         |    140     if(ctx->digestCtx) { | 
|         |    141 	sc_md_close(ctx->digestCtx); | 
|         |    142     } | 
|         |    143     memset(ctx, 0, sizeof(xmlSecSymbianCryptoHmacCtx)); | 
|         |    144 } | 
|         |    145  | 
|         |    146 /** | 
|         |    147  * xmlSecSymbianCryptoHmacNodeRead: | 
|         |    148  * | 
|         |    149  * HMAC (http://www.w3.org/TR/xmldsig-core/#sec-HMAC): | 
|         |    150  * | 
|         |    151  * The HMAC algorithm (RFC2104 [HMAC]) takes the truncation length in bits  | 
|         |    152  * as a parameter; if the parameter is not specified then all the bits of the  | 
|         |    153  * hash are output. An example of an HMAC SignatureMethod element:   | 
|         |    154  * <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"> | 
|         |    155  *   <HMACOutputLength>128</HMACOutputLength> | 
|         |    156  * </SignatureMethod> | 
|         |    157  *  | 
|         |    158  * Schema Definition: | 
|         |    159  *  | 
|         |    160  * <simpleType name="HMACOutputLengthType"> | 
|         |    161  *   <restriction base="integer"/> | 
|         |    162  * </simpleType> | 
|         |    163  *      | 
|         |    164  * DTD: | 
|         |    165  *      | 
|         |    166  * <!ELEMENT HMACOutputLength (#PCDATA)> | 
|         |    167  */ | 
|         |    168 static int | 
|         |    169 xmlSecSymbianCryptoHmacNodeRead(xmlSecTransformPtr transform,  | 
|         |    170                                                 xmlNodePtr node,  | 
|         |    171                                                 xmlSecTransformCtxPtr transformCtx) { | 
|         |    172     xmlSecSymbianCryptoHmacCtxPtr ctx; | 
|         |    173     xmlNodePtr cur; | 
|         |    174  | 
|         |    175     xmlSecAssert2(xmlSecSymbianCryptoHmacCheckId(transform), -1); | 
|         |    176     xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecSymbianCryptoHmacSize), -1); | 
|         |    177     xmlSecAssert2(node, -1); | 
|         |    178     xmlSecAssert2(transformCtx, -1); | 
|         |    179  | 
|         |    180     ctx = xmlSecSymbianCryptoHmacGetCtx(transform); | 
|         |    181     xmlSecAssert2(ctx, -1); | 
|         |    182  | 
|         |    183     cur = xmlSecGetNextElementNode(node->children);  | 
|         |    184     if((cur) && xmlSecCheckNodeName(cur, xmlSecNodeHMACOutputLength, xmlSecDSigNs)) {   | 
|         |    185 	xmlChar *content; | 
|         |    186 	 | 
|         |    187 	content = xmlNodeGetContent(cur); | 
|         |    188 	if(content) { | 
|         |    189 	    ctx->dgstSize = atoi((char*)content);	     | 
|         |    190 	    xmlFree(content); | 
|         |    191 	} | 
|         |    192 	cur = xmlSecGetNextElementNode(cur->next); | 
|         |    193     } | 
|         |    194      | 
|         |    195     if(cur) { | 
|         |    196 	xmlSecError(XMLSEC_ERRORS_HERE, | 
|         |    197 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    198 		    xmlSecNodeGetName(cur), | 
|         |    199 		    XMLSEC_ERRORS_R_INVALID_NODE, | 
|         |    200 		    "no nodes expected"); | 
|         |    201 	return(-1); | 
|         |    202     } | 
|         |    203     return(0);  | 
|         |    204 } | 
|         |    205  | 
|         |    206  | 
|         |    207 static int   | 
|         |    208 xmlSecSymbianCryptoHmacSetKeyReq(xmlSecTransformPtr transform,  xmlSecKeyReqPtr keyReq) { | 
|         |    209     xmlSecSymbianCryptoHmacCtxPtr ctx; | 
|         |    210  | 
|         |    211     xmlSecAssert2(xmlSecSymbianCryptoHmacCheckId(transform), -1); | 
|         |    212     xmlSecAssert2((transform->operation == xmlSecTransformOperationSign)  | 
|         |    213                                 || (transform->operation == xmlSecTransformOperationVerify), -1); | 
|         |    214     xmlSecAssert2(keyReq, -1); | 
|         |    215     xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecSymbianCryptoHmacSize), -1); | 
|         |    216  | 
|         |    217     ctx = xmlSecSymbianCryptoHmacGetCtx(transform); | 
|         |    218     xmlSecAssert2(ctx, -1); | 
|         |    219  | 
|         |    220     keyReq->keyId  = xmlSecSymbianCryptoKeyDataHmacId; | 
|         |    221     keyReq->keyType= xmlSecKeyDataTypeSymmetric; | 
|         |    222     if(transform->operation == xmlSecTransformOperationSign) { | 
|         |    223 	keyReq->keyUsage = xmlSecKeyUsageSign; | 
|         |    224     } else { | 
|         |    225 	keyReq->keyUsage = xmlSecKeyUsageVerify; | 
|         |    226     } | 
|         |    227      | 
|         |    228     return(0); | 
|         |    229 } | 
|         |    230  | 
|         |    231 static int | 
|         |    232 xmlSecSymbianCryptoHmacSetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key) { | 
|         |    233     xmlSecSymbianCryptoHmacCtxPtr ctx; | 
|         |    234     xmlSecKeyDataPtr value; | 
|         |    235     xmlSecBufferPtr buffer;     | 
|         |    236     int ret; | 
|         |    237      | 
|         |    238     xmlSecAssert2(xmlSecSymbianCryptoHmacCheckId(transform), -1); | 
|         |    239     xmlSecAssert2((transform->operation == xmlSecTransformOperationSign)  | 
|         |    240                                 || (transform->operation == xmlSecTransformOperationVerify), -1); | 
|         |    241     xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecSymbianCryptoHmacSize), -1); | 
|         |    242     xmlSecAssert2(key, -1); | 
|         |    243  | 
|         |    244     ctx = xmlSecSymbianCryptoHmacGetCtx(transform); | 
|         |    245     xmlSecAssert2(ctx, -1); | 
|         |    246     xmlSecAssert2(ctx->digestCtx, -1); | 
|         |    247      | 
|         |    248     value = xmlSecKeyGetValue(key); | 
|         |    249     xmlSecAssert2(xmlSecKeyDataCheckId(value, xmlSecSymbianCryptoKeyDataHmacId), -1); | 
|         |    250  | 
|         |    251     buffer = xmlSecKeyDataBinaryValueGetBuffer(value); | 
|         |    252     xmlSecAssert2(buffer, -1); | 
|         |    253  | 
|         |    254     if(xmlSecBufferGetSize(buffer) == 0) { | 
|         |    255 	xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    256 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    257 		    NULL, | 
|         |    258 		    XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE, | 
|         |    259 		    "key is empty"); | 
|         |    260 	return(-1);     | 
|         |    261     }     | 
|         |    262     ret = sc_md_setkey(ctx->digestCtx, xmlSecBufferGetData(buffer),  | 
|         |    263 			xmlSecBufferGetSize(buffer));			 | 
|         |    264     if(ret != 0) { | 
|         |    265 	xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    266 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    267 		    "gcry_md_setkey", | 
|         |    268 		    XMLSEC_ERRORS_R_CRYPTO_FAILED, | 
|         |    269 		    "ret=%d", ret); | 
|         |    270 	return(-1); | 
|         |    271     } | 
|         |    272     return(0); | 
|         |    273 } | 
|         |    274  | 
|         |    275 static int | 
|         |    276 xmlSecSymbianCryptoHmacVerify(xmlSecTransformPtr transform,  | 
|         |    277 			const xmlSecByte* data, xmlSecSize dataSize, | 
|         |    278 			xmlSecTransformCtxPtr transformCtx) { | 
|         |    279     static xmlSecByte last_byte_masks[] = 	 | 
|         |    280 		{ 0xFF, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; | 
|         |    281  | 
|         |    282     xmlSecSymbianCryptoHmacCtxPtr ctx; | 
|         |    283     xmlSecByte mask; | 
|         |    284          | 
|         |    285     xmlSecAssert2(xmlSecTransformIsValid(transform), -1); | 
|         |    286     xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecSymbianCryptoHmacSize), -1); | 
|         |    287     xmlSecAssert2(transform->operation == xmlSecTransformOperationVerify, -1); | 
|         |    288     xmlSecAssert2(transform->status == xmlSecTransformStatusFinished, -1); | 
|         |    289     xmlSecAssert2(data, -1); | 
|         |    290     xmlSecAssert2(transformCtx, -1); | 
|         |    291  | 
|         |    292     ctx = xmlSecSymbianCryptoHmacGetCtx(transform); | 
|         |    293     xmlSecAssert2(ctx, -1); | 
|         |    294     xmlSecAssert2(ctx->digestCtx, -1); | 
|         |    295     xmlSecAssert2(ctx->dgstSize > 0, -1); | 
|         |    296      | 
|         |    297     /* compare the digest size in bytes */ | 
|         |    298     if(dataSize != ((ctx->dgstSize + 7) / 8)){ | 
|         |    299 	xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    300 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    301 		    NULL, | 
|         |    302 		    XMLSEC_ERRORS_R_INVALID_SIZE, | 
|         |    303 		    "data=%d;dgst=%d", | 
|         |    304 		    dataSize, ((ctx->dgstSize + 7) / 8)); | 
|         |    305 	transform->status = xmlSecTransformStatusFail; | 
|         |    306 	return(0); | 
|         |    307     } | 
|         |    308  | 
|         |    309     /* we check the last byte separatelly */ | 
|         |    310     xmlSecAssert2(dataSize > 0, -1); | 
|         |    311     mask = last_byte_masks[ctx->dgstSize % 8]; | 
|         |    312     if((ctx->dgst[dataSize - 1] & mask) != (data[dataSize - 1]  & mask)) { | 
|         |    313 	xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    314 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    315 		    NULL, | 
|         |    316 		    XMLSEC_ERRORS_R_DATA_NOT_MATCH, | 
|         |    317 		    "data and digest do not match (last byte)"); | 
|         |    318 	transform->status = xmlSecTransformStatusFail; | 
|         |    319 	return(0); | 
|         |    320     } | 
|         |    321  | 
|         |    322     /* now check the rest of the digest */ | 
|         |    323     if((dataSize > 1) && (memcmp(ctx->dgst, data, dataSize - 1) != 0)) { | 
|         |    324 	xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    325 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    326 		    NULL, | 
|         |    327 		    XMLSEC_ERRORS_R_DATA_NOT_MATCH, | 
|         |    328 		    "data and digest do not match"); | 
|         |    329 	transform->status = xmlSecTransformStatusFail; | 
|         |    330 	return(0); | 
|         |    331     } | 
|         |    332      | 
|         |    333     transform->status = xmlSecTransformStatusOk; | 
|         |    334     return(0); | 
|         |    335 } | 
|         |    336  | 
|         |    337 static int  | 
|         |    338 xmlSecSymbianCryptoHmacExecute(xmlSecTransformPtr transform,  | 
|         |    339                                             int last,  | 
|         |    340                                             xmlSecTransformCtxPtr transformCtx) { | 
|         |    341     xmlSecSymbianCryptoHmacCtxPtr ctx; | 
|         |    342     xmlSecBufferPtr in, out; | 
|         |    343     const xmlSecByte* dgst; | 
|         |    344     xmlSecSize dgstSize; | 
|         |    345     int ret; | 
|         |    346      | 
|         |    347     xmlSecAssert2(xmlSecSymbianCryptoHmacCheckId(transform), -1); | 
|         |    348     xmlSecAssert2((transform->operation == xmlSecTransformOperationSign)  | 
|         |    349                                 || (transform->operation == xmlSecTransformOperationVerify), -1); | 
|         |    350     xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecSymbianCryptoHmacSize), -1); | 
|         |    351     xmlSecAssert2(transformCtx, -1); | 
|         |    352  | 
|         |    353     ctx = xmlSecSymbianCryptoHmacGetCtx(transform); | 
|         |    354     xmlSecAssert2(ctx, -1); | 
|         |    355     xmlSecAssert2(ctx->digestCtx, -1); | 
|         |    356  | 
|         |    357     in = &(transform->inBuf); | 
|         |    358     out = &(transform->outBuf); | 
|         |    359  | 
|         |    360     if(transform->status == xmlSecTransformStatusNone) { | 
|         |    361 	transform->status = xmlSecTransformStatusWorking; | 
|         |    362     } | 
|         |    363      | 
|         |    364     if(transform->status == xmlSecTransformStatusWorking) { | 
|         |    365 	xmlSecSize inSize; | 
|         |    366  | 
|         |    367 	inSize = xmlSecBufferGetSize(in); | 
|         |    368 	if(inSize > 0) { | 
|         |    369 	    sc_md_write(ctx->digestCtx, xmlSecBufferGetData(in), inSize); | 
|         |    370 	     | 
|         |    371 	    ret = xmlSecBufferRemoveHead(in, inSize); | 
|         |    372 	    if(ret < 0) { | 
|         |    373 		xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    374 			    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    375 			    "xmlSecBufferRemoveHead", | 
|         |    376 			    XMLSEC_ERRORS_R_XMLSEC_FAILED, | 
|         |    377 			    "size=%d", inSize); | 
|         |    378 		return(-1); | 
|         |    379 	    } | 
|         |    380 	} | 
|         |    381 	if(last) {	     | 
|         |    382 	    /* get the final digest */ | 
|         |    383 	    dgstSize = sc_md_get_algo_dlen(ctx->digestCtx); | 
|         |    384 	    sc_md_final(ctx->digestCtx);	     | 
|         |    385 	    dgst = sc_md_read(ctx->digestCtx, ctx->digest); | 
|         |    386 	    if(!dgst) { | 
|         |    387 		xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    388 			    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    389 			    "gcry_md_read", | 
|         |    390 			    XMLSEC_ERRORS_R_CRYPTO_FAILED, | 
|         |    391 			    XMLSEC_ERRORS_NO_MESSAGE); | 
|         |    392 	        return(-1); | 
|         |    393 	    } | 
|         |    394 	     | 
|         |    395 	    /* copy it to our internal buffer */ | 
|         |    396 	    //dgstSize = sc_md_get_algo_dlen(ctx->digest); | 
|         |    397 	    xmlSecAssert2(dgstSize > 0, -1); | 
|         |    398 	    xmlSecAssert2(dgstSize <= sizeof(ctx->dgst), -1); | 
|         |    399 	    memcpy(ctx->dgst, dgst, dgstSize); | 
|         |    400  | 
|         |    401 	    /* check/set the result digest size */ | 
|         |    402 	    if(ctx->dgstSize == 0) { | 
|         |    403 		ctx->dgstSize = dgstSize * 8; /* no dgst size specified, use all we have */ | 
|         |    404 	    } else if(ctx->dgstSize <= 8 * dgstSize) { | 
|         |    405 		dgstSize = ((ctx->dgstSize + 7) / 8); /* we need to truncate result digest */ | 
|         |    406 	    } else { | 
|         |    407 		xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    408 			    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    409 			    NULL, | 
|         |    410 			    XMLSEC_ERRORS_R_INVALID_SIZE, | 
|         |    411 			    "result-bits=%d;required-bits=%d", | 
|         |    412 			    8 * dgstSize, ctx->dgstSize); | 
|         |    413 		return(-1); | 
|         |    414 	    } | 
|         |    415  | 
|         |    416 	    if(transform->operation == xmlSecTransformOperationSign) { | 
|         |    417 		ret = xmlSecBufferAppend(out, ctx->dgst, dgstSize); | 
|         |    418 		if(ret < 0) { | 
|         |    419 		    xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    420 				xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    421 				"xmlSecBufferAppend", | 
|         |    422 				XMLSEC_ERRORS_R_XMLSEC_FAILED, | 
|         |    423 				"size=%d", dgstSize); | 
|         |    424 		    return(-1); | 
|         |    425 		} | 
|         |    426 	    } | 
|         |    427 	    transform->status = xmlSecTransformStatusFinished; | 
|         |    428 	} | 
|         |    429     } else if(transform->status == xmlSecTransformStatusFinished) { | 
|         |    430 	/* the only way we can get here is if there is no input */ | 
|         |    431 	xmlSecAssert2(xmlSecBufferGetSize(&(transform->inBuf)) == 0, -1); | 
|         |    432     } else { | 
|         |    433 	xmlSecError(XMLSEC_ERRORS_HERE,  | 
|         |    434 		    xmlSecErrorsSafeString(xmlSecTransformGetName(transform)), | 
|         |    435 		    NULL, | 
|         |    436 		    XMLSEC_ERRORS_R_INVALID_STATUS, | 
|         |    437 		    "size=%d", transform->status); | 
|         |    438 	return(-1); | 
|         |    439     } | 
|         |    440      | 
|         |    441     return(0); | 
|         |    442 } | 
|         |    443  | 
|         |    444 /**  | 
|         |    445  * HMAC SHA1 | 
|         |    446  */ | 
|         |    447 static xmlSecTransformKlass xmlSecSymbianCryptoHmacSha1Klass = { | 
|         |    448     /* klass/object sizes */ | 
|         |    449     sizeof(xmlSecTransformKlass),		/* xmlSecSize klassSize */ | 
|         |    450     xmlSecSymbianCryptoHmacSize,			/* xmlSecSize objSize */ | 
|         |    451  | 
|         |    452     xmlSecNameHmacSha1,				/* const xmlChar* name; */ | 
|         |    453     xmlSecHrefHmacSha1, 			/* const xmlChar *href; */ | 
|         |    454     xmlSecTransformUsageSignatureMethod,	/* xmlSecTransformUsage usage; */ | 
|         |    455      | 
|         |    456     xmlSecSymbianCryptoHmacInitialize,			/* xmlSecTransformInitializeMethod initialize; */ | 
|         |    457     xmlSecSymbianCryptoHmacFinalize,			/* xmlSecTransformFinalizeMethod finalize; */ | 
|         |    458     xmlSecSymbianCryptoHmacNodeRead,			/* xmlSecTransformNodeReadMethod readNode; */ | 
|         |    459     NULL,					/* xmlSecTransformNodeWriteMethod writeNode; */ | 
|         |    460     xmlSecSymbianCryptoHmacSetKeyReq,			/* xmlSecTransformSetKeyReqMethod setKeyReq; */ | 
|         |    461     xmlSecSymbianCryptoHmacSetKey,			/* xmlSecTransformSetKeyMethod setKey; */ | 
|         |    462     xmlSecSymbianCryptoHmacVerify,			/* xmlSecTransformValidateMethod validate; */ | 
|         |    463     xmlSecCrpytoGetDataTypeMethod,		/* xmlSecTransformGetDataTypeMethod getDataType; */ | 
|         |    464     xmlSecCryptoPushBinMethod,		/* xmlSecTransformPushBinMethod pushBin; */ | 
|         |    465     xmlSecCryptoPopBinMethod,		/* xmlSecTransformPopBinMethod popBin; */ | 
|         |    466     NULL,					/* xmlSecTransformPushXmlMethod pushXml; */ | 
|         |    467     NULL,					/* xmlSecTransformPopXmlMethod popXml; */ | 
|         |    468     xmlSecSymbianCryptoHmacExecute,			/* xmlSecTransformExecuteMethod execute; */ | 
|         |    469      | 
|         |    470     NULL,					/* void* reserved0; */ | 
|         |    471     NULL,					/* void* reserved1; */ | 
|         |    472 }; | 
|         |    473  | 
|         |    474 /**  | 
|         |    475  * xmlSecSymbianCryptoTransformHmacSha1GetKlass: | 
|         |    476  * | 
|         |    477  * The HMAC-SHA1 transform klass. | 
|         |    478  * | 
|         |    479  * Returns the HMAC-SHA1 transform klass. | 
|         |    480  */ | 
|         |    481 EXPORT_C | 
|         |    482 xmlSecTransformId  | 
|         |    483 xmlSecSymbianCryptoTransformHmacSha1GetKlass(void) { | 
|         |    484     return(&xmlSecSymbianCryptoHmacSha1Klass); | 
|         |    485 } | 
|         |    486  | 
|         |    487 /**  | 
|         |    488  * HMAC Ripemd160 | 
|         |    489  */ | 
|         |    490 static xmlSecTransformKlass xmlSecSymbianCryptoHmacRipemd160Klass = { | 
|         |    491     /* klass/object sizes */ | 
|         |    492     sizeof(xmlSecTransformKlass),		/* xmlSecSize klassSize */ | 
|         |    493     xmlSecSymbianCryptoHmacSize,			/* xmlSecSize objSize */ | 
|         |    494  | 
|         |    495     xmlSecNameHmacRipemd160,			/* const xmlChar* name; */ | 
|         |    496     xmlSecHrefHmacRipemd160, 			/* const xmlChar* href; */ | 
|         |    497     xmlSecTransformUsageSignatureMethod,	/* xmlSecTransformUsage usage; */ | 
|         |    498      | 
|         |    499     xmlSecSymbianCryptoHmacInitialize,			/* xmlSecTransformInitializeMethod initialize; */ | 
|         |    500     xmlSecSymbianCryptoHmacFinalize,			/* xmlSecTransformFinalizeMethod finalize; */ | 
|         |    501     xmlSecSymbianCryptoHmacNodeRead,			/* xmlSecTransformNodeReadMethod readNode; */ | 
|         |    502     NULL,					/* xmlSecTransformNodeWriteMethod writeNode; */ | 
|         |    503     xmlSecSymbianCryptoHmacSetKeyReq,			/* xmlSecTransformSetKeyReqMethod setKeyReq; */ | 
|         |    504     xmlSecSymbianCryptoHmacSetKey,			/* xmlSecTransformSetKeyMethod setKey; */ | 
|         |    505     xmlSecSymbianCryptoHmacVerify,			/* xmlSecTransformValidateMethod validate; */ | 
|         |    506     xmlSecCrpytoGetDataTypeMethod,		/* xmlSecTransformGetDataTypeMethod getDataType; */ | 
|         |    507     xmlSecCryptoPushBinMethod,		/* xmlSecTransformPushBinMethod pushBin; */ | 
|         |    508     xmlSecCryptoPopBinMethod,		/* xmlSecTransformPopBinMethod popBin; */ | 
|         |    509     NULL,					/* xmlSecTransformPushXmlMethod pushXml; */ | 
|         |    510     NULL,					/* xmlSecTransformPopXmlMethod popXml; */ | 
|         |    511     xmlSecSymbianCryptoHmacExecute,			/* xmlSecTransformExecuteMethod execute; */ | 
|         |    512      | 
|         |    513     NULL,					/* void* reserved0; */ | 
|         |    514     NULL,					/* void* reserved1; */ | 
|         |    515 }; | 
|         |    516  | 
|         |    517 /**  | 
|         |    518  * xmlSecSymbianCryptoTransformHmacRipemd160GetKlass: | 
|         |    519  * | 
|         |    520  * The HMAC-RIPEMD160 transform klass. | 
|         |    521  * | 
|         |    522  * Returns the HMAC-RIPEMD160 transform klass. | 
|         |    523  */ | 
|         |    524 EXPORT_C | 
|         |    525 xmlSecTransformId  | 
|         |    526 xmlSecSymbianCryptoTransformHmacRipemd160GetKlass(void) { | 
|         |    527     return(&xmlSecSymbianCryptoHmacRipemd160Klass); | 
|         |    528 } | 
|         |    529  | 
|         |    530 /**  | 
|         |    531  * HMAC Md5 | 
|         |    532  */ | 
|         |    533 static xmlSecTransformKlass xmlSecSymbianCryptoHmacMd5Klass = { | 
|         |    534     /* klass/object sizes */ | 
|         |    535     sizeof(xmlSecTransformKlass),		/* xmlSecSize klassSize */ | 
|         |    536     xmlSecSymbianCryptoHmacSize,			/* xmlSecSize objSize */ | 
|         |    537  | 
|         |    538     xmlSecNameHmacMd5,				/* const xmlChar* name; */ | 
|         |    539     xmlSecHrefHmacMd5, 				/* const xmlChar* href; */ | 
|         |    540     xmlSecTransformUsageSignatureMethod,	/* xmlSecTransformUsage usage; */ | 
|         |    541      | 
|         |    542     xmlSecSymbianCryptoHmacInitialize,			/* xmlSecTransformInitializeMethod initialize; */ | 
|         |    543     xmlSecSymbianCryptoHmacFinalize,			/* xmlSecTransformFinalizeMethod finalize; */ | 
|         |    544     xmlSecSymbianCryptoHmacNodeRead,			/* xmlSecTransformNodeReadMethod readNode; */ | 
|         |    545     NULL,					/* xmlSecTransformNodeWriteMethod writeNode; */ | 
|         |    546     xmlSecSymbianCryptoHmacSetKeyReq,			/* xmlSecTransformSetKeyReqMethod setKeyReq; */ | 
|         |    547     xmlSecSymbianCryptoHmacSetKey,			/* xmlSecTransformSetKeyMethod setKey; */ | 
|         |    548     xmlSecSymbianCryptoHmacVerify,			/* xmlSecTransformValidateMethod validate; */ | 
|         |    549     xmlSecCrpytoGetDataTypeMethod,		/* xmlSecTransformGetDataTypeMethod getDataType; */ | 
|         |    550     xmlSecCryptoPushBinMethod,		/* xmlSecTransformPushBinMethod pushBin; */ | 
|         |    551     xmlSecCryptoPopBinMethod,		/* xmlSecTransformPopBinMethod popBin; */ | 
|         |    552     NULL,					/* xmlSecTransformPushXmlMethod pushXml; */ | 
|         |    553     NULL,					/* xmlSecTransformPopXmlMethod popXml; */ | 
|         |    554     xmlSecSymbianCryptoHmacExecute,			/* xmlSecTransformExecuteMethod execute; */ | 
|         |    555      | 
|         |    556     NULL,					/* void* reserved0; */ | 
|         |    557     NULL,					/* void* reserved1; */ | 
|         |    558 }; | 
|         |    559  | 
|         |    560 /**  | 
|         |    561  * xmlSecSymbianCryptoTransformHmacMd5GetKlass: | 
|         |    562  * | 
|         |    563  * The HMAC-MD5 transform klass. | 
|         |    564  * | 
|         |    565  * Returns the HMAC-MD5 transform klass. | 
|         |    566  */ | 
|         |    567 EXPORT_C | 
|         |    568 xmlSecTransformId  | 
|         |    569 xmlSecSymbianCryptoTransformHmacMd5GetKlass(void) { | 
|         |    570     return(&xmlSecSymbianCryptoHmacMd5Klass); | 
|         |    571 } | 
|         |    572  | 
|         |    573 #endif /* XMLSEC_NO_HMAC */ |