swrng-provider

A SecureRandomSPI that makes SwiftRNG devices available to SecureRandom.

License

License

Categories

Categories

IDE Development Tools
GroupId

GroupId

ky.korins
ArtifactId

ArtifactId

swrng-provider
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

swrng-provider
A SecureRandomSPI that makes SwiftRNG devices available to SecureRandom.
Project URL

Project URL

https://github.com/catap/swrng-provider
Source Code Management

Source Code Management

https://github.com/catap/swrng-provider

Download swrng-provider

How to add to project

<!-- https://jarcasting.com/artifacts/ky.korins/swrng-provider/ -->
<dependency>
    <groupId>ky.korins</groupId>
    <artifactId>swrng-provider</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/ky.korins/swrng-provider/
implementation 'ky.korins:swrng-provider:1.0.0'
// https://jarcasting.com/artifacts/ky.korins/swrng-provider/
implementation ("ky.korins:swrng-provider:1.0.0")
'ky.korins:swrng-provider:jar:1.0.0'
<dependency org="ky.korins" name="swrng-provider" rev="1.0.0">
  <artifact name="swrng-provider" type="jar" />
</dependency>
@Grapes(
@Grab(group='ky.korins', module='swrng-provider', version='1.0.0')
)
libraryDependencies += "ky.korins" % "swrng-provider" % "1.0.0"
[ky.korins/swrng-provider "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.github.purejavacomm : purejavacomm jar 1.0.1.RELEASE

test (1)

Group / Artifact Type Version
junit : junit jar 3.8.1

Project Modules

There are no modules declared in this project.

SwiftRNG SecureRandomSPI

A SecureRandomSPI that makes SwiftRNG devices available to SecureRandom.

This code automatically detect attached devices on Linux and macOS, and when a machine has more of one SwiftRNG it uses round-robin algorithm to balance getRandomBytes calls between devices.

To use it you should add this provider to dependency like

<dependency>
  <groupId>ky.korins</groupId>
  <artifactId>swrng-provider</artifactId>
  <version>1.0.0</version>
</dependency>

and use via specified instance:

  SecureRandom random = SecureRandom.getInstance("SwiftRNG");

But you should configure it. The easy way is adding this security provider by hand:

  Security.addProvider(new SwiftRNGProvider());

or you can add it to java.security as

security.provider.N=SwiftRNG

where N should be the value of the last provider incremented by 1.

You can also select one or more devices that this code should use. For example we would like to use SwiftRNG that attached as /dev/cu.usbmodemSWRNGP000A0061 we can do:

SecureRandom random = SecureRandom.getInstance("SwiftRNG", new SwiftRNGParameters(Collections.singletonList("/dev/cu.usbmodemSWRNGP000A0061")));

or you can specified at java.security comma separated list of used devices such as:

securerandom.swiftrng.devices=/dev/cu.usbmodemSWRNGP000A0061,/dev/cu.usbmodemSWRNGP000A0062

and this is the only way to use this provider at Windows where you can get path to the device by mode.

Thus, this code is using locking to prevent parallel using the device and this add limitation that only one SecureRandom instance can be created per device that is thread safe.

You also can test your configuration by running a main method from ky.korins.swrng.SwiftRNGDevices that returns all found devices like that

SwiftRNGDevice{path=/dev/cu.usbmodemSWRNGP000A0061, model='SWRNGPRO', version='V2.1', serialNumber='XXX'}
SwiftRNGDevice{path=/dev/cu.usbmodemSWRNGP000A0062, model='SWRNGPRO', version='V2.1', serialNumber='XXX'}

Versions

Version
1.0.0