-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMAC is a form of MAC that utilizes a block cipher instead of a hash function. Support for CMAC via PKCS#11 was recently introduced to NSS allowing us to add support for it here. Related: https://bugzilla.mozilla.org/show_bug.cgi?id=1570501 Signed-off-by: Alexander Scheel <[email protected]>
- Loading branch information
Showing
7 changed files
with
100 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.jss.crypto; | ||
|
||
import java.security.NoSuchAlgorithmException; | ||
import java.util.Hashtable; | ||
|
||
import org.mozilla.jss.asn1.OBJECT_IDENTIFIER; | ||
|
||
/** | ||
* Algorithms for performing CMACs. These can be used to create | ||
* MessageDigests. | ||
*/ | ||
public class CMACAlgorithm extends DigestAlgorithm { | ||
|
||
protected CMACAlgorithm(int oidIndex, String name, OBJECT_IDENTIFIER oid, | ||
int outputSize) { | ||
super(oidIndex, name, oid, outputSize); | ||
|
||
if (oid != null && oidMap.get(oid) == null) { | ||
oidMap.put(oid, this); | ||
} | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////// | ||
// OID mapping | ||
/////////////////////////////////////////////////////////////////////// | ||
private static Hashtable<OBJECT_IDENTIFIER, CMACAlgorithm> oidMap = new Hashtable<>(); | ||
|
||
/** | ||
* Looks up the CMAC algorithm with the given OID. | ||
* | ||
* @param oid OID. | ||
* @return CMAC algorithm. | ||
* @exception NoSuchAlgorithmException If no registered CMAC algorithm | ||
* has the given OID. | ||
*/ | ||
public static CMACAlgorithm fromOID(OBJECT_IDENTIFIER oid) | ||
throws NoSuchAlgorithmException | ||
{ | ||
Object alg = oidMap.get(oid); | ||
if (alg == null) { | ||
throw new NoSuchAlgorithmException(); | ||
} else { | ||
return (CMACAlgorithm) alg; | ||
} | ||
} | ||
|
||
/** | ||
* CMAC AES-X. This is a Message Authentication Code that uses a | ||
* symmetric key together with the AES cipher to create a form of | ||
* signature. | ||
*/ | ||
public static final CMACAlgorithm AES128 = new CMACAlgorithm(CKM_AES_CMAC, "AES128-CMAC", null, 16); | ||
public static final CMACAlgorithm AES192 = new CMACAlgorithm(CKM_AES_CMAC, "AES192-CMAC", null, 16); | ||
public static final CMACAlgorithm AES256 = new CMACAlgorithm(CKM_AES_CMAC, "AES256-CMAC", null, 16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters