1 /*
2 * XML Security Library (http://www.aleksey.com/xmlsec).
3 *
4 *
5 * This is free software; see Copyright file in the source
6 * distribution for preciese wording.
7 *
8 * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
9 */
10 /**
11 * SECTION:hmac
12 * @Short_description: HMAC transforms implementation for GCrypt.
13 * @Stability: Private
14 *
15 */
16
17 #ifndef XMLSEC_NO_HMAC
18 #include "globals.h"
19
20 #include <string.h>
21
22 #include <gcrypt.h>
23
24 #include <xmlsec/xmlsec.h>
25 #include <xmlsec/xmltree.h>
26 #include <xmlsec/keys.h>
27 #include <xmlsec/transforms.h>
28 #include <xmlsec/errors.h>
29
30 #include <xmlsec/gcrypt/app.h>
31 #include <xmlsec/gcrypt/crypto.h>
32
33 /* sizes in bits */
34 #define XMLSEC_GCRYPT_MIN_HMAC_SIZE 80
35 #define XMLSEC_GCRYPT_MAX_HMAC_SIZE (128 * 8)
36
37 /**************************************************************************
38 *
39 * Configuration
40 *
41 *****************************************************************************/
42 static int g_xmlsec_gcrypt_hmac_min_length = XMLSEC_GCRYPT_MIN_HMAC_SIZE;
43
44 /**
45 * xmlSecGCryptHmacGetMinOutputLength:
46 *
47 * Gets the value of min HMAC length.
48 *
49 * Returns: the min HMAC output length
50 */
xmlSecGCryptHmacGetMinOutputLength(void)51 int xmlSecGCryptHmacGetMinOutputLength(void)
52 {
53 return g_xmlsec_gcrypt_hmac_min_length;
54 }
55
56 /**
57 * xmlSecGCryptHmacSetMinOutputLength:
58 * @min_length: the new min length
59 *
60 * Sets the min HMAC output length
61 */
xmlSecGCryptHmacSetMinOutputLength(int min_length)62 void xmlSecGCryptHmacSetMinOutputLength(int min_length)
63 {
64 g_xmlsec_gcrypt_hmac_min_length = min_length;
65 }
66
67 /**************************************************************************
68 *
69 * Internal GCRYPT HMAC CTX
70 *
71 *****************************************************************************/
72 typedef struct _xmlSecGCryptHmacCtx xmlSecGCryptHmacCtx, *xmlSecGCryptHmacCtxPtr;
73 struct _xmlSecGCryptHmacCtx {
74 int digest;
75 gcry_md_hd_t digestCtx;
76 xmlSecByte dgst[XMLSEC_GCRYPT_MAX_HMAC_SIZE / 8];
77 xmlSecSize dgstSize; /* dgst size in bits */
78 };
79
80 /******************************************************************************
81 *
82 * HMAC transforms
83 *
84 * xmlSecGCryptHmacCtx is located after xmlSecTransform
85 *
86 *****************************************************************************/
87 #define xmlSecGCryptHmacGetCtx(transform) \
88 ((xmlSecGCryptHmacCtxPtr)(((xmlSecByte*)(transform)) + sizeof(xmlSecTransform)))
89 #define xmlSecGCryptHmacSize \
90 (sizeof(xmlSecTransform) + sizeof(xmlSecGCryptHmacCtx))
91
92 static int xmlSecGCryptHmacCheckId (xmlSecTransformPtr transform);
93 static int xmlSecGCryptHmacInitialize (xmlSecTransformPtr transform);
94 static void xmlSecGCryptHmacFinalize (xmlSecTransformPtr transform);
95 static int xmlSecGCryptHmacNodeRead (xmlSecTransformPtr transform,
96 xmlNodePtr node,
97 xmlSecTransformCtxPtr transformCtx);
98 static int xmlSecGCryptHmacSetKeyReq (xmlSecTransformPtr transform,
99 xmlSecKeyReqPtr keyReq);
100 static int xmlSecGCryptHmacSetKey (xmlSecTransformPtr transform,
101 xmlSecKeyPtr key);
102 static int xmlSecGCryptHmacVerify (xmlSecTransformPtr transform,
103 const xmlSecByte* data,
104 xmlSecSize dataSize,
105 xmlSecTransformCtxPtr transformCtx);
106 static int xmlSecGCryptHmacExecute (xmlSecTransformPtr transform,
107 int last,
108 xmlSecTransformCtxPtr transformCtx);
109
110 static int
xmlSecGCryptHmacCheckId(xmlSecTransformPtr transform)111 xmlSecGCryptHmacCheckId(xmlSecTransformPtr transform) {
112
113 #ifndef XMLSEC_NO_SHA1
114 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha1Id)) {
115 return(1);
116 } else
117 #endif /* XMLSEC_NO_SHA1 */
118
119 #ifndef XMLSEC_NO_SHA256
120 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha256Id)) {
121 return(1);
122 } else
123 #endif /* XMLSEC_NO_SHA256 */
124
125 #ifndef XMLSEC_NO_SHA384
126 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha384Id)) {
127 return(1);
128 } else
129 #endif /* XMLSEC_NO_SHA384 */
130
131 #ifndef XMLSEC_NO_SHA512
132 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha512Id)) {
133 return(1);
134 } else
135 #endif /* XMLSEC_NO_SHA512 */
136
137 #ifndef XMLSEC_NO_RIPEMD160
138 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacRipemd160Id)) {
139 return(1);
140 } else
141 #endif /* XMLSEC_NO_RIPEMD160 */
142
143 #ifndef XMLSEC_NO_MD5
144 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacMd5Id)) {
145 return(1);
146 } else
147 #endif /* XMLSEC_NO_MD5 */
148
149 /* not found */
150 {
151 return(0);
152 }
153
154 /* just in case */
155 return(0);
156 }
157
158
159 static int
xmlSecGCryptHmacInitialize(xmlSecTransformPtr transform)160 xmlSecGCryptHmacInitialize(xmlSecTransformPtr transform) {
161 xmlSecGCryptHmacCtxPtr ctx;
162 gcry_error_t err;
163
164 xmlSecAssert2(xmlSecGCryptHmacCheckId(transform), -1);
165 xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecGCryptHmacSize), -1);
166
167 ctx = xmlSecGCryptHmacGetCtx(transform);
168 xmlSecAssert2(ctx != NULL, -1);
169
170 memset(ctx, 0, sizeof(xmlSecGCryptHmacCtx));
171
172 #ifndef XMLSEC_NO_SHA1
173 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha1Id)) {
174 ctx->digest = GCRY_MD_SHA1;
175 } else
176 #endif /* XMLSEC_NO_SHA1 */
177
178 #ifndef XMLSEC_NO_SHA256
179 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha256Id)) {
180 ctx->digest = GCRY_MD_SHA256;
181 } else
182 #endif /* XMLSEC_NO_SHA256 */
183
184 #ifndef XMLSEC_NO_SHA384
185 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha384Id)) {
186 ctx->digest = GCRY_MD_SHA384;
187 } else
188 #endif /* XMLSEC_NO_SHA384 */
189
190 #ifndef XMLSEC_NO_SHA512
191 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacSha512Id)) {
192 ctx->digest = GCRY_MD_SHA512;
193 } else
194 #endif /* XMLSEC_NO_SHA512 */
195
196 #ifndef XMLSEC_NO_RIPEMD160
197 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacRipemd160Id)) {
198 ctx->digest = GCRY_MD_RMD160;
199 } else
200 #endif /* XMLSEC_NO_RIPEMD160 */
201
202 #ifndef XMLSEC_NO_MD5
203 if(xmlSecTransformCheckId(transform, xmlSecGCryptTransformHmacMd5Id)) {
204 ctx->digest = GCRY_MD_MD5;
205 } else
206 #endif /* XMLSEC_NO_MD5 */
207
208 /* not found */
209 {
210 xmlSecInvalidTransfromError(transform)
211 return(-1);
212 }
213
214 /* open context */
215 err = gcry_md_open(&ctx->digestCtx, ctx->digest, GCRY_MD_FLAG_HMAC | GCRY_MD_FLAG_SECURE); /* we are paranoid */
216 if(err != GPG_ERR_NO_ERROR) {
217 xmlSecGCryptError("gcry_md_open", err,
218 xmlSecTransformGetName(transform));
219 return(-1);
220 }
221
222 return(0);
223 }
224
225 static void
xmlSecGCryptHmacFinalize(xmlSecTransformPtr transform)226 xmlSecGCryptHmacFinalize(xmlSecTransformPtr transform) {
227 xmlSecGCryptHmacCtxPtr ctx;
228
229 xmlSecAssert(xmlSecGCryptHmacCheckId(transform));
230 xmlSecAssert(xmlSecTransformCheckSize(transform, xmlSecGCryptHmacSize));
231
232 ctx = xmlSecGCryptHmacGetCtx(transform);
233 xmlSecAssert(ctx != NULL);
234
235 if(ctx->digestCtx != NULL) {
236 gcry_md_close(ctx->digestCtx);
237 }
238 memset(ctx, 0, sizeof(xmlSecGCryptHmacCtx));
239 }
240
241 /**
242 * xmlSecGCryptHmacNodeRead:
243 *
244 * HMAC (http://www.w3.org/TR/xmldsig-core/#sec-HMAC):
245 *
246 * The HMAC algorithm (RFC2104 [HMAC]) takes the truncation length in bits
247 * as a parameter; if the parameter is not specified then all the bits of the
248 * hash are output. An example of an HMAC SignatureMethod element:
249 * <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1">
250 * <HMACOutputLength>128</HMACOutputLength>
251 * </SignatureMethod>
252 *
253 * Schema Definition:
254 *
255 * <simpleType name="HMACOutputLengthType">
256 * <restriction base="integer"/>
257 * </simpleType>
258 *
259 * DTD:
260 *
261 * <!ELEMENT HMACOutputLength (#PCDATA)>
262 */
263 static int
xmlSecGCryptHmacNodeRead(xmlSecTransformPtr transform,xmlNodePtr node,xmlSecTransformCtxPtr transformCtx)264 xmlSecGCryptHmacNodeRead(xmlSecTransformPtr transform, xmlNodePtr node, xmlSecTransformCtxPtr transformCtx) {
265 xmlSecGCryptHmacCtxPtr ctx;
266 xmlNodePtr cur;
267
268 xmlSecAssert2(xmlSecGCryptHmacCheckId(transform), -1);
269 xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecGCryptHmacSize), -1);
270 xmlSecAssert2(node != NULL, -1);
271 xmlSecAssert2(transformCtx != NULL, -1);
272
273 ctx = xmlSecGCryptHmacGetCtx(transform);
274 xmlSecAssert2(ctx != NULL, -1);
275
276 cur = xmlSecGetNextElementNode(node->children);
277 if((cur != NULL) && xmlSecCheckNodeName(cur, xmlSecNodeHMACOutputLength, xmlSecDSigNs)) {
278 xmlChar *content;
279
280 content = xmlNodeGetContent(cur);
281 if(content != NULL) {
282 ctx->dgstSize = atoi((char*)content);
283 xmlFree(content);
284 }
285
286 /* Ensure that HMAC length is greater than min specified.
287 Otherwise, an attacker can set this length to 0 or very
288 small value
289 */
290 if((int)ctx->dgstSize < xmlSecGCryptHmacGetMinOutputLength()) {
291 xmlSecInvalidNodeContentError(cur, xmlSecTransformGetName(transform),
292 "HMAC output length is too small");
293 return(-1);
294 }
295
296 cur = xmlSecGetNextElementNode(cur->next);
297 }
298
299 if(cur != NULL) {
300 xmlSecUnexpectedNodeError(cur, xmlSecTransformGetName(transform));
301 return(-1);
302 }
303 return(0);
304 }
305
306
307 static int
xmlSecGCryptHmacSetKeyReq(xmlSecTransformPtr transform,xmlSecKeyReqPtr keyReq)308 xmlSecGCryptHmacSetKeyReq(xmlSecTransformPtr transform, xmlSecKeyReqPtr keyReq) {
309 xmlSecGCryptHmacCtxPtr ctx;
310
311 xmlSecAssert2(xmlSecGCryptHmacCheckId(transform), -1);
312 xmlSecAssert2((transform->operation == xmlSecTransformOperationSign) || (transform->operation == xmlSecTransformOperationVerify), -1);
313 xmlSecAssert2(keyReq != NULL, -1);
314 xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecGCryptHmacSize), -1);
315
316 ctx = xmlSecGCryptHmacGetCtx(transform);
317 xmlSecAssert2(ctx != NULL, -1);
318
319 keyReq->keyId = xmlSecGCryptKeyDataHmacId;
320 keyReq->keyType= xmlSecKeyDataTypeSymmetric;
321 if(transform->operation == xmlSecTransformOperationSign) {
322 keyReq->keyUsage = xmlSecKeyUsageSign;
323 } else {
324 keyReq->keyUsage = xmlSecKeyUsageVerify;
325 }
326
327 return(0);
328 }
329
330 static int
xmlSecGCryptHmacSetKey(xmlSecTransformPtr transform,xmlSecKeyPtr key)331 xmlSecGCryptHmacSetKey(xmlSecTransformPtr transform, xmlSecKeyPtr key) {
332 xmlSecGCryptHmacCtxPtr ctx;
333 xmlSecKeyDataPtr value;
334 xmlSecBufferPtr buffer;
335 gcry_error_t err;
336
337 xmlSecAssert2(xmlSecGCryptHmacCheckId(transform), -1);
338 xmlSecAssert2((transform->operation == xmlSecTransformOperationSign) || (transform->operation == xmlSecTransformOperationVerify), -1);
339 xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecGCryptHmacSize), -1);
340 xmlSecAssert2(key != NULL, -1);
341
342 ctx = xmlSecGCryptHmacGetCtx(transform);
343 xmlSecAssert2(ctx != NULL, -1);
344 xmlSecAssert2(ctx->digestCtx != NULL, -1);
345
346 value = xmlSecKeyGetValue(key);
347 xmlSecAssert2(xmlSecKeyDataCheckId(value, xmlSecGCryptKeyDataHmacId), -1);
348
349 buffer = xmlSecKeyDataBinaryValueGetBuffer(value);
350 xmlSecAssert2(buffer != NULL, -1);
351
352 if(xmlSecBufferGetSize(buffer) == 0) {
353 xmlSecInvalidZeroKeyDataSizeError(xmlSecTransformGetName(transform));
354 return(-1);
355 }
356
357 err = gcry_md_setkey(ctx->digestCtx, xmlSecBufferGetData(buffer),
358 xmlSecBufferGetSize(buffer));
359 if(err != GPG_ERR_NO_ERROR) {
360 xmlSecGCryptError("gcry_md_setkey", err,
361 xmlSecTransformGetName(transform));
362 return(-1);
363 }
364 return(0);
365 }
366
367 static int
xmlSecGCryptHmacVerify(xmlSecTransformPtr transform,const xmlSecByte * data,xmlSecSize dataSize,xmlSecTransformCtxPtr transformCtx)368 xmlSecGCryptHmacVerify(xmlSecTransformPtr transform,
369 const xmlSecByte* data, xmlSecSize dataSize,
370 xmlSecTransformCtxPtr transformCtx) {
371 static xmlSecByte last_byte_masks[] =
372 { 0xFF, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
373
374 xmlSecGCryptHmacCtxPtr ctx;
375 xmlSecByte mask;
376
377 xmlSecAssert2(xmlSecTransformIsValid(transform), -1);
378 xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecGCryptHmacSize), -1);
379 xmlSecAssert2(transform->operation == xmlSecTransformOperationVerify, -1);
380 xmlSecAssert2(transform->status == xmlSecTransformStatusFinished, -1);
381 xmlSecAssert2(data != NULL, -1);
382 xmlSecAssert2(transformCtx != NULL, -1);
383
384 ctx = xmlSecGCryptHmacGetCtx(transform);
385 xmlSecAssert2(ctx != NULL, -1);
386 xmlSecAssert2(ctx->digestCtx != NULL, -1);
387 xmlSecAssert2(ctx->dgstSize > 0, -1);
388
389 /* compare the digest size in bytes */
390 if(dataSize != ((ctx->dgstSize + 7) / 8)) {
391 xmlSecInvalidSizeError("HMAC digest size",
392 dataSize, ((ctx->dgstSize + 7) / 8),
393 xmlSecTransformGetName(transform));
394 transform->status = xmlSecTransformStatusFail;
395 return(0);
396 }
397
398 /* we check the last byte separately */
399 xmlSecAssert2(dataSize > 0, -1);
400 mask = last_byte_masks[ctx->dgstSize % 8];
401 if((ctx->dgst[dataSize - 1] & mask) != (data[dataSize - 1] & mask)) {
402 xmlSecOtherError(XMLSEC_ERRORS_R_DATA_NOT_MATCH,
403 xmlSecTransformGetName(transform),
404 "data and digest do not match (last byte)");
405 transform->status = xmlSecTransformStatusFail;
406 return(0);
407 }
408
409 /* now check the rest of the digest */
410 if((dataSize > 1) && (memcmp(ctx->dgst, data, dataSize - 1) != 0)) {
411 xmlSecOtherError(XMLSEC_ERRORS_R_DATA_NOT_MATCH,
412 xmlSecTransformGetName(transform),
413 "data and digest do not match");
414 transform->status = xmlSecTransformStatusFail;
415 return(0);
416 }
417
418 transform->status = xmlSecTransformStatusOk;
419 return(0);
420 }
421
422 static int
xmlSecGCryptHmacExecute(xmlSecTransformPtr transform,int last,xmlSecTransformCtxPtr transformCtx)423 xmlSecGCryptHmacExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxPtr transformCtx) {
424 xmlSecGCryptHmacCtxPtr ctx;
425 xmlSecBufferPtr in, out;
426 xmlSecByte* dgst;
427 xmlSecSize dgstSize;
428 int ret;
429
430 xmlSecAssert2(xmlSecGCryptHmacCheckId(transform), -1);
431 xmlSecAssert2((transform->operation == xmlSecTransformOperationSign) || (transform->operation == xmlSecTransformOperationVerify), -1);
432 xmlSecAssert2(xmlSecTransformCheckSize(transform, xmlSecGCryptHmacSize), -1);
433 xmlSecAssert2(transformCtx != NULL, -1);
434
435 ctx = xmlSecGCryptHmacGetCtx(transform);
436 xmlSecAssert2(ctx != NULL, -1);
437 xmlSecAssert2(ctx->digestCtx != NULL, -1);
438
439 in = &(transform->inBuf);
440 out = &(transform->outBuf);
441
442 if(transform->status == xmlSecTransformStatusNone) {
443 transform->status = xmlSecTransformStatusWorking;
444 }
445
446 if(transform->status == xmlSecTransformStatusWorking) {
447 xmlSecSize inSize;
448
449 inSize = xmlSecBufferGetSize(in);
450 if(inSize > 0) {
451 gcry_md_write(ctx->digestCtx, xmlSecBufferGetData(in), inSize);
452
453 ret = xmlSecBufferRemoveHead(in, inSize);
454 if(ret < 0) {
455 xmlSecInternalError2("xmlSecBufferRemoveHead",
456 xmlSecTransformGetName(transform),
457 "size=%d", inSize);
458 return(-1);
459 }
460 }
461 if(last) {
462 /* get the final digest */
463 gcry_md_final(ctx->digestCtx);
464 dgst = gcry_md_read(ctx->digestCtx, ctx->digest);
465 if(dgst == NULL) {
466 xmlSecGCryptError("gcry_md_read", GPG_ERR_NO_ERROR,
467 xmlSecTransformGetName(transform));
468 return(-1);
469 }
470
471 /* copy it to our internal buffer */
472 dgstSize = gcry_md_get_algo_dlen(ctx->digest);
473 xmlSecAssert2(dgstSize > 0, -1);
474 xmlSecAssert2(dgstSize <= sizeof(ctx->dgst), -1);
475 memcpy(ctx->dgst, dgst, dgstSize);
476
477 /* check/set the result digest size */
478 if(ctx->dgstSize == 0) {
479 ctx->dgstSize = dgstSize * 8; /* no dgst size specified, use all we have */
480 } else if(ctx->dgstSize <= 8 * dgstSize) {
481 dgstSize = ((ctx->dgstSize + 7) / 8); /* we need to truncate result digest */
482 } else {
483 xmlSecInvalidSizeLessThanError("HMAC digest (bits)",
484 8 * dgstSize, ctx->dgstSize,
485 xmlSecTransformGetName(transform));
486 return(-1);
487 }
488
489 if(transform->operation == xmlSecTransformOperationSign) {
490 ret = xmlSecBufferAppend(out, ctx->dgst, dgstSize);
491 if(ret < 0) {
492 xmlSecInternalError2("xmlSecBufferAppend",
493 xmlSecTransformGetName(transform),
494 "size=%d", dgstSize);
495 return(-1);
496 }
497 }
498 transform->status = xmlSecTransformStatusFinished;
499 }
500 } else if(transform->status == xmlSecTransformStatusFinished) {
501 /* the only way we can get here is if there is no input */
502 xmlSecAssert2(xmlSecBufferGetSize(&(transform->inBuf)) == 0, -1);
503 } else {
504 xmlSecInvalidTransfromStatusError(transform);
505 return(-1);
506 }
507
508 return(0);
509 }
510
511 #ifndef XMLSEC_NO_SHA1
512 /******************************************************************************
513 *
514 * HMAC SHA1
515 *
516 ******************************************************************************/
517 static xmlSecTransformKlass xmlSecGCryptHmacSha1Klass = {
518 /* klass/object sizes */
519 sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */
520 xmlSecGCryptHmacSize, /* xmlSecSize objSize */
521
522 xmlSecNameHmacSha1, /* const xmlChar* name; */
523 xmlSecHrefHmacSha1, /* const xmlChar *href; */
524 xmlSecTransformUsageSignatureMethod, /* xmlSecTransformUsage usage; */
525
526 xmlSecGCryptHmacInitialize, /* xmlSecTransformInitializeMethod initialize; */
527 xmlSecGCryptHmacFinalize, /* xmlSecTransformFinalizeMethod finalize; */
528 xmlSecGCryptHmacNodeRead, /* xmlSecTransformNodeReadMethod readNode; */
529 NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
530 xmlSecGCryptHmacSetKeyReq, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
531 xmlSecGCryptHmacSetKey, /* xmlSecTransformSetKeyMethod setKey; */
532 xmlSecGCryptHmacVerify, /* xmlSecTransformValidateMethod validate; */
533 xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
534 xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
535 xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
536 NULL, /* xmlSecTransformPushXmlMethod pushXml; */
537 NULL, /* xmlSecTransformPopXmlMethod popXml; */
538 xmlSecGCryptHmacExecute, /* xmlSecTransformExecuteMethod execute; */
539
540 NULL, /* void* reserved0; */
541 NULL, /* void* reserved1; */
542 };
543
544 /**
545 * xmlSecGCryptTransformHmacSha1GetKlass:
546 *
547 * The HMAC-SHA1 transform klass.
548 *
549 * Returns: the HMAC-SHA1 transform klass.
550 */
551 xmlSecTransformId
xmlSecGCryptTransformHmacSha1GetKlass(void)552 xmlSecGCryptTransformHmacSha1GetKlass(void) {
553 return(&xmlSecGCryptHmacSha1Klass);
554 }
555 #endif /* XMLSEC_NO_SHA1 */
556
557 #ifndef XMLSEC_NO_SHA256
558 /******************************************************************************
559 *
560 * HMAC SHA256
561 *
562 ******************************************************************************/
563 static xmlSecTransformKlass xmlSecGCryptHmacSha256Klass = {
564 /* klass/object sizes */
565 sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */
566 xmlSecGCryptHmacSize, /* xmlSecSize objSize */
567
568 xmlSecNameHmacSha256, /* const xmlChar* name; */
569 xmlSecHrefHmacSha256, /* const xmlChar *href; */
570 xmlSecTransformUsageSignatureMethod, /* xmlSecTransformUsage usage; */
571
572 xmlSecGCryptHmacInitialize, /* xmlSecTransformInitializeMethod initialize; */
573 xmlSecGCryptHmacFinalize, /* xmlSecTransformFinalizeMethod finalize; */
574 xmlSecGCryptHmacNodeRead, /* xmlSecTransformNodeReadMethod readNode; */
575 NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
576 xmlSecGCryptHmacSetKeyReq, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
577 xmlSecGCryptHmacSetKey, /* xmlSecTransformSetKeyMethod setKey; */
578 xmlSecGCryptHmacVerify, /* xmlSecTransformValidateMethod validate; */
579 xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
580 xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
581 xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
582 NULL, /* xmlSecTransformPushXmlMethod pushXml; */
583 NULL, /* xmlSecTransformPopXmlMethod popXml; */
584 xmlSecGCryptHmacExecute, /* xmlSecTransformExecuteMethod execute; */
585
586 NULL, /* void* reserved0; */
587 NULL, /* void* reserved1; */
588 };
589
590 /**
591 * xmlSecGCryptTransformHmacSha256GetKlass:
592 *
593 * The HMAC-SHA256 transform klass.
594 *
595 * Returns: the HMAC-SHA256 transform klass.
596 */
597 xmlSecTransformId
xmlSecGCryptTransformHmacSha256GetKlass(void)598 xmlSecGCryptTransformHmacSha256GetKlass(void) {
599 return(&xmlSecGCryptHmacSha256Klass);
600 }
601 #endif /* XMLSEC_NO_SHA256 */
602
603 #ifndef XMLSEC_NO_SHA384
604 /******************************************************************************
605 *
606 * HMAC SHA384
607 *
608 ******************************************************************************/
609 static xmlSecTransformKlass xmlSecGCryptHmacSha384Klass = {
610 /* klass/object sizes */
611 sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */
612 xmlSecGCryptHmacSize, /* xmlSecSize objSize */
613
614 xmlSecNameHmacSha384, /* const xmlChar* name; */
615 xmlSecHrefHmacSha384, /* const xmlChar *href; */
616 xmlSecTransformUsageSignatureMethod, /* xmlSecTransformUsage usage; */
617
618 xmlSecGCryptHmacInitialize, /* xmlSecTransformInitializeMethod initialize; */
619 xmlSecGCryptHmacFinalize, /* xmlSecTransformFinalizeMethod finalize; */
620 xmlSecGCryptHmacNodeRead, /* xmlSecTransformNodeReadMethod readNode; */
621 NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
622 xmlSecGCryptHmacSetKeyReq, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
623 xmlSecGCryptHmacSetKey, /* xmlSecTransformSetKeyMethod setKey; */
624 xmlSecGCryptHmacVerify, /* xmlSecTransformValidateMethod validate; */
625 xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
626 xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
627 xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
628 NULL, /* xmlSecTransformPushXmlMethod pushXml; */
629 NULL, /* xmlSecTransformPopXmlMethod popXml; */
630 xmlSecGCryptHmacExecute, /* xmlSecTransformExecuteMethod execute; */
631
632 NULL, /* void* reserved0; */
633 NULL, /* void* reserved1; */
634 };
635
636 /**
637 * xmlSecGCryptTransformHmacSha384GetKlass:
638 *
639 * The HMAC-SHA384 transform klass.
640 *
641 * Returns: the HMAC-SHA384 transform klass.
642 */
643 xmlSecTransformId
xmlSecGCryptTransformHmacSha384GetKlass(void)644 xmlSecGCryptTransformHmacSha384GetKlass(void) {
645 return(&xmlSecGCryptHmacSha384Klass);
646 }
647 #endif /* XMLSEC_NO_SHA384 */
648
649 #ifndef XMLSEC_NO_SHA512
650 /******************************************************************************
651 *
652 * HMAC SHA512
653 *
654 ******************************************************************************/
655 static xmlSecTransformKlass xmlSecGCryptHmacSha512Klass = {
656 /* klass/object sizes */
657 sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */
658 xmlSecGCryptHmacSize, /* xmlSecSize objSize */
659
660 xmlSecNameHmacSha512, /* const xmlChar* name; */
661 xmlSecHrefHmacSha512, /* const xmlChar *href; */
662 xmlSecTransformUsageSignatureMethod, /* xmlSecTransformUsage usage; */
663
664 xmlSecGCryptHmacInitialize, /* xmlSecTransformInitializeMethod initialize; */
665 xmlSecGCryptHmacFinalize, /* xmlSecTransformFinalizeMethod finalize; */
666 xmlSecGCryptHmacNodeRead, /* xmlSecTransformNodeReadMethod readNode; */
667 NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
668 xmlSecGCryptHmacSetKeyReq, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
669 xmlSecGCryptHmacSetKey, /* xmlSecTransformSetKeyMethod setKey; */
670 xmlSecGCryptHmacVerify, /* xmlSecTransformValidateMethod validate; */
671 xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
672 xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
673 xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
674 NULL, /* xmlSecTransformPushXmlMethod pushXml; */
675 NULL, /* xmlSecTransformPopXmlMethod popXml; */
676 xmlSecGCryptHmacExecute, /* xmlSecTransformExecuteMethod execute; */
677
678 NULL, /* void* reserved0; */
679 NULL, /* void* reserved1; */
680 };
681
682 /**
683 * xmlSecGCryptTransformHmacSha512GetKlass:
684 *
685 * The HMAC-SHA512 transform klass.
686 *
687 * Returns: the HMAC-SHA512 transform klass.
688 */
689 xmlSecTransformId
xmlSecGCryptTransformHmacSha512GetKlass(void)690 xmlSecGCryptTransformHmacSha512GetKlass(void) {
691 return(&xmlSecGCryptHmacSha512Klass);
692 }
693 #endif /* XMLSEC_NO_SHA512 */
694
695
696 #ifndef XMLSEC_NO_RIPEMD160
697 /******************************************************************************
698 *
699 * HMAC Ripemd160
700 *
701 ******************************************************************************/
702 static xmlSecTransformKlass xmlSecGCryptHmacRipemd160Klass = {
703 /* klass/object sizes */
704 sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */
705 xmlSecGCryptHmacSize, /* xmlSecSize objSize */
706
707 xmlSecNameHmacRipemd160, /* const xmlChar* name; */
708 xmlSecHrefHmacRipemd160, /* const xmlChar* href; */
709 xmlSecTransformUsageSignatureMethod, /* xmlSecTransformUsage usage; */
710
711 xmlSecGCryptHmacInitialize, /* xmlSecTransformInitializeMethod initialize; */
712 xmlSecGCryptHmacFinalize, /* xmlSecTransformFinalizeMethod finalize; */
713 xmlSecGCryptHmacNodeRead, /* xmlSecTransformNodeReadMethod readNode; */
714 NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
715 xmlSecGCryptHmacSetKeyReq, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
716 xmlSecGCryptHmacSetKey, /* xmlSecTransformSetKeyMethod setKey; */
717 xmlSecGCryptHmacVerify, /* xmlSecTransformValidateMethod validate; */
718 xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
719 xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
720 xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
721 NULL, /* xmlSecTransformPushXmlMethod pushXml; */
722 NULL, /* xmlSecTransformPopXmlMethod popXml; */
723 xmlSecGCryptHmacExecute, /* xmlSecTransformExecuteMethod execute; */
724
725 NULL, /* void* reserved0; */
726 NULL, /* void* reserved1; */
727 };
728
729 /**
730 * xmlSecGCryptTransformHmacRipemd160GetKlass:
731 *
732 * The HMAC-RIPEMD160 transform klass.
733 *
734 * Returns: the HMAC-RIPEMD160 transform klass.
735 */
736 xmlSecTransformId
xmlSecGCryptTransformHmacRipemd160GetKlass(void)737 xmlSecGCryptTransformHmacRipemd160GetKlass(void) {
738 return(&xmlSecGCryptHmacRipemd160Klass);
739 }
740 #endif /* XMLSEC_NO_RIPEMD160 */
741
742 #ifndef XMLSEC_NO_MD5
743 /******************************************************************************
744 *
745 * HMAC MD5
746 *
747 ******************************************************************************/
748 static xmlSecTransformKlass xmlSecGCryptHmacMd5Klass = {
749 /* klass/object sizes */
750 sizeof(xmlSecTransformKlass), /* xmlSecSize klassSize */
751 xmlSecGCryptHmacSize, /* xmlSecSize objSize */
752
753 xmlSecNameHmacMd5, /* const xmlChar* name; */
754 xmlSecHrefHmacMd5, /* const xmlChar* href; */
755 xmlSecTransformUsageSignatureMethod, /* xmlSecTransformUsage usage; */
756
757 xmlSecGCryptHmacInitialize, /* xmlSecTransformInitializeMethod initialize; */
758 xmlSecGCryptHmacFinalize, /* xmlSecTransformFinalizeMethod finalize; */
759 xmlSecGCryptHmacNodeRead, /* xmlSecTransformNodeReadMethod readNode; */
760 NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
761 xmlSecGCryptHmacSetKeyReq, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
762 xmlSecGCryptHmacSetKey, /* xmlSecTransformSetKeyMethod setKey; */
763 xmlSecGCryptHmacVerify, /* xmlSecTransformValidateMethod validate; */
764 xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
765 xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
766 xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
767 NULL, /* xmlSecTransformPushXmlMethod pushXml; */
768 NULL, /* xmlSecTransformPopXmlMethod popXml; */
769 xmlSecGCryptHmacExecute, /* xmlSecTransformExecuteMethod execute; */
770
771 NULL, /* void* reserved0; */
772 NULL, /* void* reserved1; */
773 };
774
775 /**
776 * xmlSecGCryptTransformHmacMd5GetKlass:
777 *
778 * The HMAC-MD5 transform klass.
779 *
780 * Returns: the HMAC-MD5 transform klass.
781 */
782 xmlSecTransformId
xmlSecGCryptTransformHmacMd5GetKlass(void)783 xmlSecGCryptTransformHmacMd5GetKlass(void) {
784 return(&xmlSecGCryptHmacMd5Klass);
785 }
786 #endif /* XMLSEC_NO_MD5 */
787
788
789 #endif /* XMLSEC_NO_HMAC */
790