Naruto / simon-speck-net

C# wrapper implementation of simon-speck-c that is SIMON and SPECK lightweight block ciphers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status Windows Build status Coverity Scan Build Status NuGet version FOSSA Status

simon-speck-net

c# wrapper implement of Naruto/simon-speck-c

simon and speck are lightweight block cipher algorithms, published by NSA.(iadgov/simon-speck)

support platforms are Desktop Platforms(Windows, macOS, Linux), Xamarin iOS and MonoAndroid.

Supports

  • algorithms and block sizes, key sizes and modes
    • speck ECB
      • 128/128
      • 128/192
      • 128/256
    • speck CTR
      • 128/128
      • 128/192
      • 128/256
  • platforms, architectures
    • windows x64
    • macOS x64
    • linux x64
    • Xamarin iOS
    • MonoAndroid

Sample

simple encrypt and decrypt code.

String plainText = "test text abcdefg.";
byte[] plainByte = System.Text.Encoding.ASCII.GetBytes(plainText);

// Speck ECB mode
using (SymmetricAlgorithm algo = new Speck())
{
    algo.BlockSize = 128;
    algo.KeySize = 128;
    
    algo.GenerateKey();
    using (ICryptoTransform encryptor = algo.CreateEncryptor() , decryptor = algo.CreateDecryptor())
    {
        byte[] plainEnc = encryptor.TransformFinalBlock(plainByte, 0, plainByte.Length);
        byte[] plainDec = decryptor.TransformFinalBlock(plainEnc, 0, plainEnc.Length);
        Console.WriteLine(System.Text.Encoding.ASCII.GetString(plainDec));
        Console.WriteLine();
    }
}

// Speck CTR mode
using (SymmetricAlgorithm algo = new SpeckCTR())
{
    algo.BlockSize = 128;
    algo.KeySize = 128;
    
    algo.GenerateIV();
    algo.GenerateKey();
    using (ICryptoTransform encryptor = algo.CreateEncryptor() , decryptor = algo.CreateDecryptor())
    {
        byte[] plainEnc = encryptor.TransformFinalBlock(plainByte, 0, plainByte.Length);
        byte[] plainDec = decryptor.TransformFinalBlock(plainEnc, 0, plainEnc.Length);
        Console.WriteLine(System.Text.Encoding.ASCII.GetString(plainDec));
        Console.WriteLine();
    }
}

development

preapre

  • mono
  • Unity (if create unity package)

get source

git clone --recursive git@github.com:Naruto/simon-speck-net.git

build

build simon-speck-net and nunit test.

cd /path/to/simon-speck-net
cd ./net
mono .nuget/nuget.exe restore
xbuild /p:TargetFrameworkVersion="v4.5" /p:Configuration=Release
mono ./packages/NUnit.ConsoleRunner.3.7.0/tools/nunit3-console.exe ./speckTest/bin/Release/speckTest.dll

or

cd /path/to/simon-speck-net
./scripts/build.sh

create nuget package

cd /path/to/simon-speck-net
./scripts/create_nuget.sh

SimonSpeckNet nuget package file is outputted to out/net directory.

create unity package

cd /path/to/simon-speck-net
./scripts/create_unitypackage.sh

SimonSpeckNet unitypackage file is outputted to out/unity directory.

update native library

update simon-speck-c sumobule

git submodule update --init --recursive

Android

export NDK_ROOT=/path/to/android-ndk-path
./scripts/plugins/deploy_android.sh

deploy each archtectures library files to net/plugins/Android/libs

iOS

./scripts/pluginsdeploy_ios.sh

deploy fat library file to net/plugins/iOS

Linux

./scripts/plugins/deploy_linux.sh

deploy .so file to net/plugins/x64

macOS

./scripts/plugins/deploy_mac.sh

deploy .dylib and .bundle files to net/plugins/x64

Windows

T.B.D

License

FOSSA Status

About

C# wrapper implementation of simon-speck-c that is SIMON and SPECK lightweight block ciphers.

License:MIT License


Languages

Language:C# 95.5%Language:Shell 4.0%Language:Batchfile 0.5%