1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 /*
21  * XSEC
22  *
23  * XSECCryptoUtils:= Helper crypo utilities that make life easier
24  *
25  * Author(s): Berin Lautenbach
26  *
27  * $Id: XSECCryptoUtils.hpp 1817863 2017-12-11 22:47:43Z scantor $
28  *
29  */
30 
31 #ifndef XSECCRYPTOUTILS_INCLUDE
32 #define XSECCRYPTOUTILS_INCLUDE
33 
34 #include <xsec/framework/XSECDefs.hpp>
35 #include <xsec/utils/XSECSafeBuffer.hpp>
36 #include <xsec/dsig/DSIGConstants.hpp>
37 
38 /**
39  * \brief Helper utilities for crypto.
40  * @ingroup crypto
41  */
42 
43 #ifdef XSEC_XKMS_ENABLED
44 // --------------------------------------------------------------------------------
45 //           XKMS Limited-Use Shared Secret handling
46 // --------------------------------------------------------------------------------
47 
48 #define XKMSAuthenticationValue                    0x01
49 #define    XKMSRevocationCodeIdenfitierEncoding1    0x02
50 #define    XKMSRevocationCodeIdenfitierEncoding2    0x03
51 #define XKMSKeyEncryption                        0x04
52 
53 int XSEC_EXPORT CalculateXKMSAuthenticationKey(unsigned char * input, int inputLen, unsigned char * output, int maxOutputLen);
54 int XSEC_EXPORT CalculateXKMSRevocationCodeIdentifierEncoding1(unsigned char * input, int inputLen, unsigned char * output, int maxOutputLen);
55 /* Calculate encoding 2 - Input is original pass phrase */
56 int XSEC_EXPORT CalculateXKMSRevocationCodeIdentifierEncoding2(unsigned char * input, int inputLen, unsigned char * output, int maxOutputLen);
57 /* Calculate encoding 2 - Input is encoding 1 */
58 int XSEC_EXPORT CalculateXKMSRevocationCodeIdentifierEncoding2From1(unsigned char * input, int inputLen, unsigned char * output, int maxOutputLen);
59 int XSEC_EXPORT CalculateXKMSKEK(unsigned char * input, int inputLen, unsigned char * output, int maxOutputLen);
60 #endif
61 
62 // --------------------------------------------------------------------------------
63 //           Some Base64 helpers
64 // --------------------------------------------------------------------------------
65 
66 XMLCh XSEC_EXPORT * EncodeToBase64XMLCh(unsigned char * input, int inputLen);
67 unsigned int XSEC_EXPORT DecodeFromBase64XMLCh(const XMLCh * input, unsigned char * output, int maxOutputLen);
68 unsigned int XSEC_EXPORT DecodeFromBase64(const char * input, unsigned char * output, int maxOutputLen);
69 
70 // --------------------------------------------------------------------------------
71 //           Some stuff to help with wierd signatures
72 // --------------------------------------------------------------------------------
73 
74 // Convert an ASN.1 format DSA signature (!!!) to the two component integers
75 // NOTE - both r and s must be at least 20 bytes long
76 
77 bool XSEC_EXPORT ASN2DSASig(const unsigned char* input, unsigned char* r, unsigned char* s);
78 
79 // --------------------------------------------------------------------------------
80 //           Calculate correct OIDs for an RSA sig
81 // --------------------------------------------------------------------------------
82 
83 unsigned char* getRSASigOID(XSECCryptoHash::HashType type, int& oidLen);
84 
85 #endif /* XSECCRYPTOUTILS_INCLUDE */
86 
87 
88