Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
justkawal committed Nov 10, 2023
0 parents commit ba1ce46
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is used to define a set of default reviewers.
* @justkawal
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: kawal
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: https://paypal.me/justkawal
42 changes: 42 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Dart

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

# Note: This workflow uses the latest stable version of the Dart SDK.
# You can specify other versions if desired, see documentation here:
# https://github.com/dart-lang/setup-dart/blob/main/README.md
# - uses: dart-lang/setup-dart@v1
- uses: dart-lang/setup-dart@9a04e6d73cca37bd455e0608d7e5092f881fd603

- name: Install dependencies
run: dart pub get

# Uncomment this step to verify the use of 'dart format' on each commit.
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze --fatal-infos

# Your project will need to have tests in test/ and a dependency on
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 1.0.0
- Initial version.

## 1.0.1
- Publish version.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (C) 2023 - Kawaljeet Singh

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Empty file added README.md
Empty file.
30 changes: 30 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

linter:
rules:
prefer_final_fields

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
42 changes: 42 additions & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:convert/convert.dart';
import 'package:merlin/merlin.dart';

void main() {
{
//Simple Transcript
final mt = Transcript('test protocol');

mt.appendMessage(Uint8List.fromList(utf8.encode('some label')),
Uint8List.fromList(utf8.encode('some data')));

final cBytes =
mt.extractBytes(Uint8List.fromList(utf8.encode('challenge')), 32);

// d5a21972d0d5fe320c0d263fac7fffb8145aa640af6e9bca177c03c7efcf0615
final cHex = hex.encode(cBytes);
print(cHex);
}

{
// Complex Transcript
final tr = Transcript('test protocol');
tr.appendMessage(utf8.encode('step1'), utf8.encode('some data'));

final data = Uint8List(1024)..fillRange(0, 1024, 99);

late List<int> chlBytes;
for (var i = 0; i < 32; i++) {
chlBytes = tr.extractBytes(utf8.encode('challenge'), 32);
tr
..appendMessage(utf8.encode('bigdata'), data)
..appendMessage(utf8.encode('challengedata'), chlBytes);
}

// a8c933f54fae76e3f9bea93648c1308e7dfa2152dd51674ff3ca438351cf003c
final chlHex = hex.encode(chlBytes);
print(chlHex);
}
}
40 changes: 40 additions & 0 deletions lib/merlin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:strobe/strobe.dart';

const merlinProtocolLabel = 'Merlin v1.0';
const domainSeparatorLabel = 'dom-sep';

class Transcript {
late Strobe s;
Transcript(String appLabel) {
s = Strobe.initStrobe(merlinProtocolLabel, Security.bit128);
appendMessage(utf8.encode(domainSeparatorLabel), utf8.encode(appLabel));
}

// Append adds the message to the transcript with the supplied label.
void appendMessage(List<int> label, List<int> message) {
final sizeBuffer = Uint8List(4);
ByteData.view(sizeBuffer.buffer)
.setUint32(0, message.length, Endian.little);

final labelSize = Uint8List.fromList([...label, ...sizeBuffer]);
s
..aD(true, labelSize)
..aD(false, message);
}

// ExtractBytes returns a buffer filled with the verifier's challenge bytes.
// The label parameter is metadata about the challenge, and is also appended to
// the transcript. See the Transcript Protocols section of the Merlin website
// for details on labels.
List<int> extractBytes(List<int> label, int outLen) {
final sizeBuffer = Uint8List(4);
ByteData.view(sizeBuffer.buffer).setUint32(0, outLen, Endian.little);

final labelSize = Uint8List.fromList([...label, ...sizeBuffer]);
s.aD(true, labelSize);

return s.prf(outLen);
}
}
15 changes: 15 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: merlin
description: A starting point for Dart libraries or applications.
version: 1.0.1
repository: https://github.com/justkawal/merlin

environment:
sdk: ^3.1.5

dependencies:
strobe: ^1.0.1

dev_dependencies:
convert: ^3.1.1
lints: ^3.0.0
test: ^1.21.0
39 changes: 39 additions & 0 deletions test/merlin_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'dart:convert';
import 'dart:typed_data';
import 'package:convert/convert.dart';
import 'package:merlin/merlin.dart';
import 'package:test/test.dart';

void main() {
test('Test Simple Transcript', () {
final mt = Transcript('test protocol');
mt.appendMessage(Uint8List.fromList(utf8.encode('some label')),
Uint8List.fromList(utf8.encode('some data')));

final cBytes =
mt.extractBytes(Uint8List.fromList(utf8.encode('challenge')), 32);
final cHex = hex.encode(cBytes);

expect(cHex,
'd5a21972d0d5fe320c0d263fac7fffb8145aa640af6e9bca177c03c7efcf0615');
});

test('Test Complex Transcript', () {
final tr = Transcript('test protocol');
tr.appendMessage(utf8.encode('step1'), utf8.encode('some data'));

final data = Uint8List(1024)..fillRange(0, 1024, 99);

late List<int> chlBytes;
for (var i = 0; i < 32; i++) {
chlBytes = tr.extractBytes(utf8.encode('challenge'), 32);
tr
..appendMessage(utf8.encode('bigdata'), data)
..appendMessage(utf8.encode('challengedata'), chlBytes);
}
final chlHex = hex.encode(chlBytes);

expect(chlHex,
'a8c933f54fae76e3f9bea93648c1308e7dfa2152dd51674ff3ca438351cf003c');
});
}

0 comments on commit ba1ce46

Please sign in to comment.