Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
179 changes: 179 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# SPDX-FileCopyrightText: 2024 Lukas Prediger <lumip@lumip.de>
# SPDX-License-Identifier: GPL-3.0-or-later

root = true

[*.cs]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

#### .NET Coding Conventions ####

# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = true
file_header_template = unset

# this. and Me. preferences
dotnet_style_qualification_for_event = false
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_property = false
dotnet_diagnostic.IDE0003.severity = none

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity
dotnet_diagnostic.IDE0047.severity = suggestion

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members

# Expression-level preferences
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true
dotnet_style_explicit_tuple_names = true
dotnet_style_namespace_match_folder = false
dotnet_style_null_propagation = true
dotnet_style_object_initializer = true
# dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true
dotnet_style_prefer_collection_expression = when_types_exactly_match
dotnet_style_prefer_compound_assignment = true
dotnet_diagnostic.IDE0054.severity = none
dotnet_diagnostic.IDE0074.severity = none
dotnet_style_prefer_conditional_expression_over_assignment = true
dotnet_style_prefer_conditional_expression_over_return = true
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
dotnet_style_prefer_inferred_anonymous_type_member_names = false
dotnet_style_prefer_inferred_tuple_names = true
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
dotnet_style_prefer_simplified_boolean_expressions = true
dotnet_style_prefer_simplified_interpolation = true

# Field preferences
dotnet_style_readonly_field = true

#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = false
csharp_style_var_for_built_in_types = false
csharp_style_var_when_type_is_apparent = false

# Expression-bodied members
csharp_style_expression_bodied_accessors = true
csharp_style_expression_bodied_constructors = false
csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_lambdas = true
csharp_style_expression_bodied_local_functions = false
csharp_style_expression_bodied_methods = false
csharp_style_expression_bodied_operators = false
csharp_style_expression_bodied_properties = true

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true
csharp_style_pattern_matching_over_is_with_cast_check = true
csharp_style_prefer_extended_property_pattern = true
csharp_style_prefer_not_pattern = true
csharp_style_prefer_pattern_matching = true
csharp_style_prefer_switch_expression = false

# Null-checking preferences
csharp_style_conditional_delegate_call = true

# Modifier preferences
csharp_prefer_static_local_function = true
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
csharp_style_prefer_readonly_struct = true
csharp_style_prefer_readonly_struct_member = true

# Code-block preferences
csharp_prefer_braces = when_multiline
csharp_prefer_simple_using_statement = true
csharp_style_namespace_declarations = block_scoped
csharp_style_prefer_method_group_conversion = true
csharp_style_prefer_primary_constructors = false
csharp_style_prefer_top_level_statements = false

# Expression-level preferences
csharp_prefer_simple_default_expression = true
csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = false
csharp_style_inlined_variable_declaration = true
csharp_style_prefer_index_operator = true
csharp_style_prefer_local_over_anonymous_function = true
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_range_operator = true
csharp_style_prefer_tuple_swap = true
# csharp_style_prefer_utf8_string_literals = false
csharp_style_throw_expression = true
# csharp_style_unused_value_assignment_preference = discard_variable
# csharp_style_unused_value_expression_statement_preference = discard_variable

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace

# # New line preferences
# csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
# csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true
# csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
# csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
# csharp_style_allow_embedded_statements_on_same_line_experimental = true

#### C# Formatting Rules ####

# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true

# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = ignore
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false

# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true

# dotnet_analyzer_diagnostic.category-Style.severity = warning
55 changes: 55 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SPDX-FileCopyrightText: 2024 Lukas Prediger <lumip@lumip.de>
# SPDX-License-Identifier: GPL-3.0-or-later
name: Tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
style_check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Check style
run: dotnet format --verify-no-changes
- name: Install reuse linter
run: sudo apt-get install -y reuse
- name: Check reuse compliance
run: reuse lint

build_and_test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Test and generate coverage report
run: |
dotnet test CompactCryptoGroupAlgebra.Tests/ --collect:"XPlat Code Coverage" --settings CompactCryptoGroupAlgebra.Tests/coverlet.runsettings
dotnet test CompactCryptoGroupAlgebra.LibCrypto.Tests/ --collect:"XPlat Code Coverage" --settings CompactCryptoGroupAlgebra.LibCrypto.Tests/coverlet.runsettings
- name: Copy coveralls report
run: |
mkdir ./CoverageResults
cp -v ./CompactCryptoGroupAlgebra.Tests/TestResults/*/coverage.info ./CoverageResults/base_coverage.info
cp -v ./CompactCryptoGroupAlgebra.LibCrypto.Tests/TestResults/*/coverage.info ./CoverageResults/libcrypto_coverage.info
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
files:
./CoverageResults/base_coverage.info
./CoverageResults/libcrypto_coverage.info
format: lcov
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ CoverageReport/
__Instrumented/
*Coverage*/
small_*curve_check.py
.reuse*
.reuse*
*TestResults*
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

8 changes: 3 additions & 5 deletions CompactCryptoGroupAlgebra.LibCrypto.Tests/BigNumberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
// terms of the OpenSSL License and the SSLeay License, the licensors of CompactCryptoGroupAlgebra.LibCrypto
// grant you additional permission to convey the resulting work.

using NUnit.Framework;

using System;
using System.Numerics;

using CompactCryptoGroupAlgebra.LibCrypto.Internal.Native;
using NUnit.Framework;

namespace CompactCryptoGroupAlgebra.LibCrypto
{
Expand Down Expand Up @@ -158,7 +156,7 @@ public void TestZero()
public void TestLength()
{
var number = new BigNumber(0x548f07);
var expected = NumberLength.FromBitLength(23);;
var expected = NumberLength.FromBitLength(23); ;

Assert.That(number.Length.Equals(expected));
}
Expand Down Expand Up @@ -188,7 +186,7 @@ public void TestToString()
int rawValue = 0x96235;
var expected = (new BigInteger(rawValue)).ToString();
var number = new BigNumber(rawValue);

Assert.That(number.ToString().Equals(expected));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!--
CompactCryptoGroupAlgebra - C# implementation of abelian group algebra for experimental cryptography

SPDX-FileCopyrightText: 2020-2021 Lukas Prediger <lumip@lumip.de>
SPDX-FileCopyrightText: 2020-2024 Lukas Prediger <lumip@lumip.de>
SPDX-License-Identifier: GPL-3.0-or-later WITH GPL-3.0-linking-exception
SPDX-FileType: SOURCE
-->
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net8</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<AssemblyName>CompactCryptoGroupAlgebra.LibCrypto.Tests</AssemblyName>
<RootNamespace>CompactCryptoGroupAlgebra.LibCrypto</RootNamespace>
Expand All @@ -21,13 +21,21 @@ SPDX-FileType: SOURCE
<Copyright>Copyright © 2021 Lukas Prediger</Copyright>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<OutputPath>bin/$(Configuration)/</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin/$(Configuration)/</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="Microsoft.CodeCoverage" Version="16.8.3" />
<PackageReference Include="NunitXml.TestLogger" Version="3.0.91" />
<PackageReference Include="coverlet.collector" Version="6.*" />
<PackageReference Include="coverlet.msbuild" Version="3.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
// terms of the OpenSSL License and the SSLeay License, the licensors of CompactCryptoGroupAlgebra.LibCrypto
// grant you additional permission to convey the resulting work.

using NUnit.Framework;

using System.Globalization;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Globalization;

using CompactCryptoGroupAlgebra.LibCrypto.EllipticCurves;
using CompactCryptoGroupAlgebra.LibCrypto.Multiplicative;
using NUnit.Framework;

namespace CompactCryptoGroupAlgebra.LibCrypto
{
Expand All @@ -54,7 +52,7 @@ FFFFFFFF FFFFFFFF C90FDAA2 2168C234 C4C6628B 80DC1CD1
29024E08 8A67CC74 020BBEA6 3B139B22 514A0879 8E3404DD
EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245
E485B576 625E7EC6 F44C42E9 A63A3620 FFFFFFFF FFFFFFFF";

BigPrime prime = BigPrime.CreateWithoutChecks(
BigInteger.Parse(Regex.Replace(primeHex, @"\s+", ""), NumberStyles.AllowHexSpecifier)
);
Expand All @@ -63,9 +61,9 @@ EF9519B3 CD3A431B 302B0A6D F25F1437 4FE1356D 6D51C245

var algebra = new MultiplicativeGroupAlgebra(prime, order, generator);
var group = new CryptoGroup<SecureBigNumber, BigNumber>(algebra);

CompactCryptoGroupAlgebra.DiffieHellmanIntegrationTests.DoDiffieHellman(group);
}

}
}
}
Loading