Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
feat: Source code compatibility wizh .NET 6.
Browse files Browse the repository at this point in the history
chore: Added all necessary options and imports.
fix: Use integers for counts in BitManipulationHelper.
  • Loading branch information
xformerfhs committed Nov 23, 2022
1 parent d063f47 commit 9205efc
Show file tree
Hide file tree
Showing 48 changed files with 566 additions and 153 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.4.0] - 2022-11-23

### Changed
- Bit manipulation uses integers for counts.
- Source code adapted for compatibility with .NET 6.
- Set all necessary options and imports in all files.
- Namespace changed to "TUPWLib".

## [2.3.3] - 2021-10-18

### Changed
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,23 @@ But it is still shorter than using the hexadecimal representation of the encrypt

The encrypted data can only be decrypted with the same key sources and the same subject string.

## Programming

The name space for the library is `TUPWLib`.
This is a change from the former version that used another name space.

The source code is compatible with `.NET 6`.
One can use the same source code for `.NET Framework 4.8` and `.NET 6`.
The solution (`.sln`) and project (`.vbproj`) files in this repository are made for `.NET Framework 4.8`.
If one wants to use `.NET 6` or later one just has to set up a `.NET 6` library project and import the files in the `Arrays`, `Crypto`, `Numbers` and `Statistics` folders.

## Command Line Program

One can write a command line program that uses the interface that is present in this library:

```csharp
using System;
using DB.BCM.TUPW;
using TUPWLib;

namespace TUPWCommandLine
{
Expand Down
4 changes: 3 additions & 1 deletion TUPWLib/Arrays/ArrayHelper.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand Down Expand Up @@ -28,6 +28,8 @@
' 2020-10-26: V1.0.4: Added a few comments re. the use of non-short-circuit logic.
' 2021-08-27: V1.1.0: Added SafeClear method.
'
Option Strict On
Option Explicit On

''' <summary>
''' Class with all the array methods missing from the <see cref="Array"/> class.
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Arrays/Base32Encoding.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2021 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand Down Expand Up @@ -28,6 +28,9 @@
' 2021-05-12: V1.3.0: Direct mapping of a byte value to a char.
'

Option Strict On
Option Explicit On

''' <summary>
''' Converts byte arrays from and to Base32 encoding either, as specified in RFC4868, or in spell-safe format.
''' </summary>
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Arrays/UnpaddedBase64.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand All @@ -25,6 +25,9 @@
' 2020-05-18: V1.0.1: Added null check.
'

Option Strict On
Option Explicit On

''' <summary>
''' Wrapper for unpadded Base64 conversions.
''' </summary>
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Crypto/ArbitraryTailPadding.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand All @@ -25,6 +25,9 @@
' 2020-08-13: V1.0.1: Improved GetPaddingByteValue method.
'

Option Strict On
Option Explicit On

''' <summary>
''' Arbitrary tail padding for block ciphers.
''' </summary>
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Crypto/ByteArrayBlinding.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand Down Expand Up @@ -27,6 +27,9 @@
' 2021-07-13: V1.1.0: Simplified blinding.
'

Option Strict On
Option Explicit On

''' <summary>
''' Blinding for byte arrays.
''' </summary>
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Crypto/CounterModeCryptoTransform.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand Down Expand Up @@ -30,6 +30,9 @@
' 2021-09-03: V2.1.0: Fortify finding: Dispose of symmetric encryption algorithm only if we instantiated it ourselves.
'

Option Strict On
Option Explicit On

Imports System.Security.Cryptography

''' <summary>
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Crypto/DataIntegrityException.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand All @@ -24,6 +24,9 @@
' 2020-04-29: V1.0.0: Created.
'

Option Strict On
Option Explicit On

Imports System.Runtime.Serialization

''' <summary>
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Crypto/FileAndKeyEncryption.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand Down Expand Up @@ -28,6 +28,9 @@
' 2021-09-03: V2.1.1: Fortify finding: Removed unused "CheckState" method.
'

Option Strict On
Option Explicit On

Imports System.IO

''' <summary>
Expand Down
18 changes: 12 additions & 6 deletions TUPWLib/Crypto/MaskedIndex.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
'
' Author: Frank Schwab, DB Systel GmbH
'
' Version: 1.2.0
' Version: 1.3.0
'
' Change history:
' 2020-05-28: V1.0.0: Created.
' 2020-06-15: V1.0.1: Clear key bytes.
' 2022-11-07: V1.1.0: Better mixing of bytes from and to buffers.
' 2022-11-08: V1.2.0: Name all constants.
' 2022-11-22: V1.3.0: Use AES.Create() for cipher creation.
'

Option Strict On
Option Explicit On

Imports System.Security.Cryptography

''' <summary>
Expand Down Expand Up @@ -181,11 +185,13 @@ Public Class MaskedIndex : Implements IDisposable

SecurePseudoRandomNumberGenerator.GetBytes(key)

Using cipher As New AesCng With {
.Mode = CipherMode.ECB,
.Padding = PaddingMode.None,
.Key = key
}
Using cipher As Aes = Aes.Create()
With cipher
.Mode = CipherMode.ECB
.Padding = PaddingMode.None
.Key = key
End With

m_Encryptor = cipher.CreateEncryptor()
End Using

Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Crypto/ProtectedByteArray.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand Down Expand Up @@ -35,6 +35,9 @@
' 2021-09-03: V3.1.1: Fortify finding: Added forgotten check for maximum count of source array.
'

Option Strict On
Option Explicit On

''' <summary>
''' Stores a byte array in a protected and obfuscated form.
''' </summary>
Expand Down
5 changes: 4 additions & 1 deletion TUPWLib/Crypto/RandomPadding.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand All @@ -26,6 +26,9 @@
' 2020-05-29: V2.0.1: Added exception comments.
'

Option Strict On
Option Explicit On

''' <summary>
''' Random padding for block ciphers.
''' </summary>
Expand Down
10 changes: 7 additions & 3 deletions TUPWLib/Crypto/SecurePseudoRandomNumberGenerator.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand All @@ -18,15 +18,19 @@
'
' Author: Frank Schwab, DB Systel GmbH
'
' Version: 1.2.0
' Version: 1.3.0
'
' Change history:
' 2020-04-21: V1.0.1: Created.
' 2020-05-15: V1.0.1: Made constants consistent with types.
' 2020-05-27: V1.1.0: Refactored function value mapping into own shared class.
' 2020-06-19: V1.2.0: Use new FunctionValueRangeMapperAPI.
' 2022-11-22: V1.3.0: Use RandomNumberGenerator.Create() to create new instance.
'

Option Strict On
Option Explicit On

Imports System.Security.Cryptography

''' <summary>
Expand All @@ -52,7 +56,7 @@ Public NotInheritable Class SecurePseudoRandomNumberGenerator
'''
''' <para><see cref="RNGCryptoServiceProvider"/> is thread-safe, so there is no need to synchronize access.</para>
''' </remarks>
Private Shared ReadOnly m_Prng As New RNGCryptoServiceProvider()
Private Shared ReadOnly m_Prng As RandomNumberGenerator = RandomNumberGenerator.Create()
#End Region

#Region "Public methods"
Expand Down
19 changes: 12 additions & 7 deletions TUPWLib/Crypto/SplitKeyEncryption.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'
' SPDX-FileCopyrightText: 2020 DB Systel GmbH
' SPDX-FileCopyrightText: 2022 DB Systel GmbH
'
' SPDX-License-Identifier: Apache-2.0
'
Expand All @@ -18,7 +18,7 @@
'
' Author: Frank Schwab, DB Systel GmbH
'
' Version: 2.3.3
' Version: 2.4.0
'
' Change history:
' 2020-05-05: V1.0.0: Created.
Expand Down Expand Up @@ -47,8 +47,12 @@
' 2021-09-03: V2.3.1: Fixed Fortify findings.
' 2021-10-18: V2.3.2: Corrected names for structure properties.
' 2021-10-18: V2.3.3: Corrected entropy threshold constant.
' 2022-11-22: V2.4.0: Use Aes.Create() for cipher creation.
'

Option Strict On
Option Explicit On

Imports System.Security.Cryptography
Imports System.Text

Expand Down Expand Up @@ -665,10 +669,11 @@ Public Class SplitKeyEncryption : Implements IDisposable
' and the "catch" part.
'
Try
Using aesCipher As New AesCng() With {
.Mode = CipherMode.CBC,
.Padding = PaddingMode.None ' Never use any of the standard paddings!!!! They are all susceptible to a padding oracle.
}
Using aesCipher As Aes = Aes.Create()
With aesCipher
.Mode = CipherMode.CBC
.Padding = PaddingMode.None ' Never use any of the standard paddings!!!! They are all susceptible to a padding oracle.
End With

Dim blockSizeInBytes As Integer = aesCipher.BlockSize >> 3

Expand Down Expand Up @@ -897,7 +902,7 @@ Public Class SplitKeyEncryption : Implements IDisposable
Private Shared Function GetCryptoTransformForCipherMode(aCipherMode As Byte, key As Byte(), iv As Byte()) As ICryptoTransform
Dim result As ICryptoTransform

Using aesAlgorithm As SymmetricAlgorithm = New AesCng()
Using aesAlgorithm As SymmetricAlgorithm = Aes.Create()
If aCipherMode <> COUNTER_CIPHER_MODE Then
aesAlgorithm.Mode = CType(aCipherMode, CipherMode)
aesAlgorithm.Padding = PaddingMode.None
Expand Down
13 changes: 13 additions & 0 deletions TUPWLib/My Project/Application.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions TUPWLib/My Project/Application.myapp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>false</MySubMain>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>1</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>
Loading

0 comments on commit 9205efc

Please sign in to comment.