forked from wolfSSL/wolfcrypt-jni
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAsn.java
More file actions
184 lines (153 loc) · 6 KB
/
Asn.java
File metadata and controls
184 lines (153 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* Asn.java
*
* Copyright (C) 2006-2026 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
package com.wolfssl.wolfcrypt;
import java.nio.ByteBuffer;
/**
* Wrapper for the native WolfCrypt ASN.1 implementation.
*
* @author wolfSSL Inc.
*/
public class Asn extends WolfObject {
/** Default Asn constructor. */
public Asn() {
}
/** Maximum encoded signature size */
public static final int MAX_ENCODED_SIG_SIZE = 512;
/* Key Sum values, from asn.h Key_Sum enum */
/** DSA key value, from asn.h Key_Sum enum */
public static final int DSAk;
/** RSA key value, from asn.h Key_Sum enum */
public static final int RSAk;
/** RSA-PSS key value, from asn.h Key_Sum enum */
public static final int RSAPSSk;
/** RSA-OAEP key value, from asn.h Key_Sum enum */
public static final int RSAESOAEPk;
/** ECDSA key value, from asn.h Key_Sum enum */
public static final int ECDSAk;
/* Hash Sum values, from oid_sum.h Hash_Sum enum */
/** MD5 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int MD5h;
/** SHA-1 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHAh;
/** SHA-224 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA224h;
/** SHA-256 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA256h;
/** SHA-384 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA384h;
/** SHA-512 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA512h;
/** SHA3-224 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA3_224h;
/** SHA3-256 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA3_256h;
/** SHA3-384 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA3_384h;
/** SHA3-512 hash OID value, from oid_sum.h Hash_Sum enum */
public static final int SHA3_512h;
static {
DSAk = getDSAk();
RSAk = getRSAk();
RSAPSSk = getRSAPSSk();
RSAESOAEPk = getRSAESOAEPk();
ECDSAk = getECDSAk();
MD5h = getMD5h();
SHAh = getSHAh();
SHA224h = getSHA224h();
SHA256h = getSHA256h();
SHA384h = getSHA384h();
SHA512h = getSHA512h();
SHA3_224h = getSHA3_224h();
SHA3_256h = getSHA3_256h();
SHA3_384h = getSHA3_384h();
SHA3_512h = getSHA3_512h();
}
/** Return value of native DSAk enum */
private static native int getDSAk();
/** Return value of native RSAk enum */
private static native int getRSAk();
/** Return value of native RSAPSSk enum */
private static native int getRSAPSSk();
/** Return value of native RSAESOAEPk enum */
private static native int getRSAESOAEPk();
/** Return value of native ECDSAk enum */
private static native int getECDSAk();
/** Return value of native MD5h enum */
private static native int getMD5h();
/** Return value of native SHAh enum */
private static native int getSHAh();
/** Return value of native SHA224h enum */
private static native int getSHA224h();
/** Return value of native SHA256h enum */
private static native int getSHA256h();
/** Return value of native SHA384h enum */
private static native int getSHA384h();
/** Return value of native SHA512h enum */
private static native int getSHA512h();
/** Return value of native SHA3_224h enum */
private static native int getSHA3_224h();
/** Return value of native SHA3_256h enum */
private static native int getSHA3_256h();
/** Return value of native SHA3_384h enum */
private static native int getSHA3_384h();
/** Return value of native SHA3_512h enum */
private static native int getSHA3_512h();
/** ASN.1 encode message digest, before it is signed
*
* @param encoded output buffer to place encoded data
* @param hash input hash to encode
* @param hashSize size of hash, bytes
* @param hashOID hash algorithm OID
*/
public static native void encodeSignature(ByteBuffer encoded,
ByteBuffer hash, long hashSize, int hashOID);
/** ASN.1 encode message digest, before it is signed
*
* @param encoded output array to place encoded data
* @param hash input hash to encode
* @param hashSize size of hash, bytes
* @param hashOID hash algorithm OID
*
* @return number of bytes written to encoded array
*/
public static native long encodeSignature(byte[] encoded,
byte[] hash, long hashSize, int hashOID);
/**
* Get hash algorithm OID from algorithm type
*
* @param type algorithm type. Comes from each algorithm class, for example:
* Sha.TYPE, Sha256.TYPE
*
* @return hash algorithm OID, for use with encodeSignature()
*/
public static native int getCTC_HashOID(int type);
/**
* Get the Algorithm Identifier from inside DER-encoded PKCS#8 key.
*
* @param pkcs8Der DER-encoded PKCS#8 private key
*
* @return Algorithm Identifier on success, will match one of the values
* for key sums (ie: Asn.RSAk, Asn.ECDSAk, etc)
*
* @throws WolfCryptException upon native error
*/
public static native int getPkcs8AlgoID(byte[] pkcs8Der);
}