Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <[email protected]>
  • Loading branch information
nguyennv committed Jan 2, 2024
1 parent c397ee3 commit 32e0b28
Show file tree
Hide file tree
Showing 120 changed files with 251 additions and 130 deletions.
4 changes: 3 additions & 1 deletion lib/src/armor/armor.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -9,6 +9,8 @@ import '../crypto/math/int_ext.dart';
import '../enum/armor_type.dart';
import '../helpers.dart';

/// ASCII Armor class
/// Author Nguyen Van Nguyen <[email protected]>
class Armor {
static const version = 'Dart PG v1.0.0';
static const comment = 'Dart Privacy Guard';
Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/asymmetric/elgamal.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -12,6 +12,7 @@ import '../math/byte_ext.dart';

/// Asymmetric block cipher using basic ElGamal algorithm.
/// Ported and modified from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class ElGamalEngine implements AsymmetricBlockCipher {
late ElGamalAsymmetricKey? _key;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/math/big_int.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

import 'dart:typed_data';

/// Author Nguyen Van Nguyen <[email protected]>
extension BigIntExt on BigInt {
int get byteLength => (bitLength + 7) >> 3;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/math/byte_ext.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

import 'dart:typed_data';

/// Author Nguyen Van Nguyen <[email protected]>
extension Uint8ListExt on Uint8List {
int toIn16([
Endian endian = Endian.big,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/math/int_ext.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

import 'dart:typed_data';

import 'package:fixnum/fixnum.dart';

/// Author Nguyen Van Nguyen <[email protected]>
extension IntExt on int {
Uint8List pack16([Endian endian = Endian.big]) => Uint8List(2)
..buffer.asByteData().setInt16(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/signer/dsa.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -14,6 +14,7 @@ import '../math/int_ext.dart';

/// Implementation of DSA (digital signature algorithm)
/// Ported and modified from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class DSASigner implements Signer {
final Digest? _digest;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/base_cipher.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
/// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
/// For the full copyright and license information, please view the LICENSE
/// file that was distributed with this source code.
Expand All @@ -15,6 +15,7 @@ export 'twofish.dart';

/// Base implementation of [BlockCipher] which provides shared methods.
/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
abstract class BaseCipher implements BlockCipher {
@override
Uint8List process(final Uint8List data) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/blowfish.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -14,6 +14,7 @@ import 'base_cipher.dart';
/// All the algorithms herein are from Applied Cryptography
/// and implement a simplified cryptography interface.
/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class BlowfishEngine extends BaseCipher {
static const _kp = [
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, // 0 - 3
Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/buffered_cipher.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -7,6 +7,7 @@ import 'dart:typed_data';
import 'package:pointycastle/api.dart';

/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class BufferedCipher {
final BlockCipher _underlyingCipher;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/camellia.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -12,6 +12,7 @@ import 'base_cipher.dart';

/// Camellia - based on RFC 3713.
/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class CamelliaEngine extends BaseCipher {
static const _blockSize = 16;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/camellia_light.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -12,6 +12,7 @@ import 'base_cipher.dart';

/// Camellia - based on RFC 3713
/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class CamelliaLightEngine extends BaseCipher {
static const _blockSize = 16;

Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/cast5.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -17,6 +17,7 @@ import 'base_cipher.dart';
///
/// and implement a simplified cryptography interface.
/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class CAST5Engine extends BaseCipher {
static const _sBox1 = [
0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/idea.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -12,6 +12,7 @@ import 'base_cipher.dart';

/// A class that provides a basic International Data Encryption Algorithm (IDEA) engine.
/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class IDEAEngine extends BaseCipher {
static const _mask = 0xffff;
static const _base = 0x10001;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/crypto/symmetric/twofish.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -12,6 +12,7 @@ import 'base_cipher.dart';

/// A class that provides Twofish encryption operations.
/// Ported from Bouncy Castle project
/// Author Nguyen Van Nguyen <[email protected]>
class TwofishEngine extends BaseCipher {
/// Q-Table 0
static const _q0 = [
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/armor_type.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Armor type
/// Author Nguyen Van Nguyen <[email protected]>
enum ArmorType {
multipartSection,
multipartLast,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/enum/compression_algorithm.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Compression algorithm enum
/// Author Nguyen Van Nguyen <[email protected]>
enum CompressionAlgorithm {
uncompressed(0),
zip(1),
Expand Down
4 changes: 3 additions & 1 deletion lib/src/enum/curve_info.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

Expand All @@ -7,6 +7,8 @@ import 'package:pointycastle/asn1.dart';
import 'hash_algorithm.dart';
import 'symmetric_algorithm.dart';

/// Curve information enum
/// Author Nguyen Van Nguyen <[email protected]>
enum CurveInfo {
prime256v1([1, 2, 840, 10045, 3, 1, 7], '1.2.840.10045.3.1.7'),
secp256k1([1, 3, 132, 0, 10], '1.3.132.0.10'),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/dh_key_size.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Author Nguyen Van Nguyen <[email protected]>
enum DHKeySize {
l1024n160(1024, 160),
l2048n224(2048, 224),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/hash_algorithm.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Hash Algorithms
/// See https://www.rfc-editor.org/rfc/rfc4880#section-9.4
/// Author Nguyen Van Nguyen <[email protected]>
enum HashAlgorithm {
md5(1),
sha1(2),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/enum/key_algorithm.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Public-Key Algorithms
/// See https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-9.1
/// Author Nguyen Van Nguyen <[email protected]>
enum KeyAlgorithm {
/// RSA (Encrypt or Sign) [HAC]
rsaEncryptSign(1),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/key_flag.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Key flag
/// Author Nguyen Van Nguyen <[email protected]>
enum KeyFlag {
/// 0x01 - This key may be used to certify other keys.
certifyKeys(1),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/key_generation_type.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Author Nguyen Van Nguyen <[email protected]>
enum KeyGenerationType { rsa, dsa, ecdsa, eddsa }
3 changes: 2 additions & 1 deletion lib/src/enum/literal_format.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Author Nguyen Van Nguyen <[email protected]>
enum LiteralFormat {
/// Binary data 'b'
binary(98),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/packet_tag.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// A list of packet types and numeric tags associated with them.
/// Author Nguyen Van Nguyen <[email protected]>
enum PacketTag {
publicKeyEncryptedSessionKey(1),
signature(2),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/revocation_key_tag.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Author Nguyen Van Nguyen <[email protected]>
enum RevocationKeyTag {
classDefault(128),
classSensitive(64);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/revocation_reason_tag.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Reason for Revocation
/// See https://tools.ietf.org/html/rfc4880#section-5.2.3.23
/// Author Nguyen Van Nguyen <[email protected]>
enum RevocationReasonTag {
/// No reason specified (key revocations or cert revocations)
noReason(0),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/rsa_key_size.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Author Nguyen Van Nguyen <[email protected]>
enum RSAKeySize {
s2048(2048),
s2560(2560),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/s2k_type.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// A string to key specifier type
/// Author Nguyen Van Nguyen <[email protected]>
enum S2kType {
simple(0),
salted(1),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/s2k_usage.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Author Nguyen Van Nguyen <[email protected]>
enum S2kUsage {
none(0),
checksum(255),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/signature_subpacket_type.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Signature subpacket type
/// Author Nguyen Van Nguyen <[email protected]>
enum SignatureSubpacketType {
signatureCreationTime(2),
signatureExpirationTime(3),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/enum/signature_type.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Author Nguyen Van Nguyen <[email protected]>
enum SignatureType {
/// Signature of a binary document.
binary(0),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/enum/support_feature.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2022-present by Nguyen Van Nguyen <[email protected]>. All rights reserved.
// Copyright 2022-present by Dart Privacy Guard project. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

/// Support Feature
/// See https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-5.2.3.25
/// Author Nguyen Van Nguyen <[email protected]>
enum SupportFeature {
/// 0x01 - Modification Detection (packets 18 and 19)
modificationDetection(1),
Expand Down
Loading

0 comments on commit 32e0b28

Please sign in to comment.