-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: added rsa4096 and ed25519 implementation #749
Open
murali-shris
wants to merge
3
commits into
trunk
Choose a base branch
from
at_chops_rsa_4096
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 44 additions & 0 deletions
44
packages/at_chops/lib/src/algorithm/ed25519_signing_algo.dart
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,44 @@ | ||
import 'dart:async'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:at_chops/src/algorithm/at_algorithm.dart'; | ||
import 'package:at_commons/at_commons.dart'; | ||
import 'package:better_cryptography/better_cryptography.dart'; | ||
|
||
/// Data signing and verification for Ed25519 - elliptic curve algorithm | ||
/// Keypair for the algorithm has to generated using [AtChopsUtil.generateEd25519KeyPair()] | ||
class Ed25519SigningAlgo implements AtSigningAlgorithm { | ||
final _algorithm = Ed25519(); | ||
SimpleKeyPair? _ed25519KeyPair; | ||
|
||
set edd25519KeyPair(SimpleKeyPair value) { | ||
_ed25519KeyPair = value; | ||
} | ||
|
||
Ed25519SigningAlgo(); | ||
|
||
@override | ||
Future<Uint8List> sign(Uint8List data) async { | ||
if (_ed25519KeyPair == null) { | ||
throw AtSigningException( | ||
'edd25519 key pair has to be set for signing operation'); | ||
} | ||
final signature = await _algorithm.sign(data, keyPair: _ed25519KeyPair!); | ||
return Uint8List.fromList(signature.bytes); | ||
} | ||
|
||
@override | ||
Future<bool> verify(Uint8List signedData, Uint8List signature, | ||
{String? publicKey}) async { | ||
if (publicKey == null) { | ||
throw AtSigningException( | ||
'public key has to be passed for signature verification'); | ||
} | ||
return await _algorithm.verify( | ||
signedData, | ||
signature: Signature(signature, | ||
publicKey: | ||
SimplePublicKey(publicKey.codeUnits, type: KeyPairType.ed25519)), | ||
); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
class KeyNames { | ||
static const String selfEncryptionKey = 'selfEncryptionKey'; | ||
static const String apkamSymmetricKey = 'apkamSymmetricKey'; | ||
static const String rsa2048EncKey = 'rsa2048EncKey'; | ||
static const String rsa4096EncKey = 'rsa4096EncKey'; | ||
} |
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,50 @@ | ||
import 'dart:math'; | ||
import 'dart:typed_data'; | ||
|
||
import 'package:at_chops/at_chops.dart'; | ||
import 'package:at_chops/src/algorithm/ed25519_signing_algo.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('A group of tests for ed25519 signing and verification', () { | ||
test('Test data signing and verification using generated keypair', | ||
() async { | ||
final ed25519KeyPair = await AtChopsUtil.generateEd25519KeyPair(); | ||
final dataToSign = 'Hello World@123!'; | ||
final signingAlgo = Ed25519SigningAlgo(); | ||
signingAlgo.edd25519KeyPair = ed25519KeyPair; | ||
final signature = | ||
await signingAlgo.sign(Uint8List.fromList(dataToSign.codeUnits)); | ||
final publicKeyBytes = (await ed25519KeyPair.extractPublicKey()).bytes; | ||
print(publicKeyBytes.length); | ||
final verifyResult = await signingAlgo.verify( | ||
Uint8List.fromList(dataToSign.codeUnits), signature, | ||
publicKey: String.fromCharCodes(publicKeyBytes)); | ||
expect(verifyResult, true); | ||
}); | ||
test('Test data signing and verification - pass incorrect public key', | ||
() async { | ||
final ed25519KeyPair = await AtChopsUtil.generateEd25519KeyPair(); | ||
final dataToSign = 'Hello World@123!'; | ||
final signingAlgo = Ed25519SigningAlgo(); | ||
signingAlgo.edd25519KeyPair = ed25519KeyPair; | ||
final signature = | ||
await signingAlgo.sign(Uint8List.fromList(dataToSign.codeUnits)); | ||
final publicKeyBytes = (await ed25519KeyPair.extractPublicKey()).bytes; | ||
print(publicKeyBytes.length); | ||
const characters = | ||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; | ||
final random = Random(); | ||
final wrongPublicKey = String.fromCharCodes( | ||
Iterable.generate( | ||
32, | ||
(_) => characters.codeUnitAt(random.nextInt(characters.length)), | ||
), | ||
); | ||
final verifyResult = await signingAlgo.verify( | ||
Uint8List.fromList(dataToSign.codeUnits), signature, | ||
publicKey: wrongPublicKey); | ||
expect(verifyResult, false); | ||
}); | ||
}); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo, should be ed not edd