pgpainless/pgpainless-core/src/main/java/org/pgpainless/algorithm/SymmetricKeyAlgorithm.java

128 lines
3.0 KiB
Java
Raw Normal View History

2021-10-07 15:48:52 +02:00
// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.algorithm;
2018-06-02 21:21:35 +02:00
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
2018-06-02 21:21:35 +02:00
import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags;
2021-04-25 13:28:33 +02:00
/**
* Enumeration of possible symmetric encryption algorithms.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-9.2">RFC4880: Symmetric-Key Algorithms</a>
*/
2018-06-02 21:21:35 +02:00
public enum SymmetricKeyAlgorithm {
2021-04-25 13:28:33 +02:00
/**
* Plaintext or unencrypted data.
*/
2018-07-02 21:40:59 +02:00
NULL (SymmetricKeyAlgorithmTags.NULL),
2021-04-25 13:28:33 +02:00
2018-07-02 21:40:59 +02:00
/**
* IDEA is deprecated.
* @deprecated use a different algorithm.
*/
2021-04-25 13:28:33 +02:00
@Deprecated
2018-07-02 21:40:59 +02:00
IDEA (SymmetricKeyAlgorithmTags.IDEA),
2021-04-25 13:28:33 +02:00
/**
* TripleDES (DES-EDE - 168 bit key derived from 192).
*/
2018-07-02 21:40:59 +02:00
TRIPLE_DES (SymmetricKeyAlgorithmTags.TRIPLE_DES),
2021-04-25 13:28:33 +02:00
/**
* CAST5 (128 bit key, as per RFC2144).
*/
2018-07-02 21:40:59 +02:00
CAST5 (SymmetricKeyAlgorithmTags.CAST5),
2021-04-25 13:28:33 +02:00
/**
* Blowfish (128 bit key, 16 rounds).
*/
2018-07-02 21:40:59 +02:00
BLOWFISH (SymmetricKeyAlgorithmTags.BLOWFISH),
2021-04-25 13:28:33 +02:00
/**
* Reserved in RFC4880.
* SAFER-SK128 (13 rounds)
*/
2018-07-02 21:40:59 +02:00
SAFER (SymmetricKeyAlgorithmTags.SAFER),
2021-04-25 13:28:33 +02:00
/**
* Reserved in RFC4880.
* Reserved for DES/SK
*/
2018-07-02 21:40:59 +02:00
DES (SymmetricKeyAlgorithmTags.DES),
2021-04-25 13:28:33 +02:00
/**
* AES with 128-bit key.
*/
2018-07-02 21:40:59 +02:00
AES_128 (SymmetricKeyAlgorithmTags.AES_128),
2021-04-25 13:28:33 +02:00
/**
* AES with 192-bit key.
*/
2018-07-02 21:40:59 +02:00
AES_192 (SymmetricKeyAlgorithmTags.AES_192),
2021-04-25 13:28:33 +02:00
/**
* AES with 256-bit key.
*/
2018-07-02 21:40:59 +02:00
AES_256 (SymmetricKeyAlgorithmTags.AES_256),
2021-04-25 13:28:33 +02:00
/**
* Twofish with 256-bit key.
*/
2018-07-02 21:40:59 +02:00
TWOFISH (SymmetricKeyAlgorithmTags.TWOFISH),
2021-04-25 13:28:33 +02:00
/**
* Reserved for Camellia with 128-bit key.
*/
2018-07-02 21:40:59 +02:00
CAMELLIA_128 (SymmetricKeyAlgorithmTags.CAMELLIA_128),
2021-04-25 13:28:33 +02:00
/**
* Reserved for Camellia with 192-bit key.
*/
2018-07-02 21:40:59 +02:00
CAMELLIA_192 (SymmetricKeyAlgorithmTags.CAMELLIA_192),
2021-04-25 13:28:33 +02:00
/**
* Reserved for Camellia with 256-bit key.
*/
2018-07-02 21:40:59 +02:00
CAMELLIA_256 (SymmetricKeyAlgorithmTags.CAMELLIA_256),
2018-06-02 21:21:35 +02:00
;
private static final Map<Integer, SymmetricKeyAlgorithm> MAP = new ConcurrentHashMap<>();
2018-06-02 21:21:35 +02:00
static {
for (SymmetricKeyAlgorithm s : SymmetricKeyAlgorithm.values()) {
MAP.put(s.algorithmId, s);
}
}
2021-04-25 13:28:33 +02:00
/**
* Return the {@link SymmetricKeyAlgorithm} enum that corresponds to the provided numeric id.
* If an invalid id is provided, null is returned.
*
* @param id numeric algorithm id
* @return symmetric key algorithm enum
*/
2018-06-19 17:14:37 +02:00
public static SymmetricKeyAlgorithm fromId(int id) {
2018-06-02 21:21:35 +02:00
return MAP.get(id);
}
private final int algorithmId;
SymmetricKeyAlgorithm(int algorithmId) {
this.algorithmId = algorithmId;
}
2021-04-25 13:28:33 +02:00
/**
* Return the numeric algorithm id of the enum.
*
* @return numeric id
*/
2018-06-02 21:21:35 +02:00
public int getAlgorithmId() {
return algorithmId;
}
}