-
Notifications
You must be signed in to change notification settings - Fork 2
Initial constant-time implementation of Base64 for generic & AVX2 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| /target | ||
| **/*.rs.bk | ||
| Cargo.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| branches: | ||
| only: | ||
| # This is where pull requests from "bors r+" are built. | ||
| - staging | ||
| # This is where pull requests from "bors try" are built. | ||
| - trying | ||
| # Not really necessary, just to get a green badge on “master” | ||
| - master | ||
| language: rust | ||
|
|
||
| jobs: | ||
| include: | ||
| - rust: stable | ||
| - rust: beta | ||
| - rust: nightly | ||
| env: FEATURES=--features=nightly | ||
| script: | ||
| - cargo test --no-default-features | ||
| - cargo test $FEATURES |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| [package] | ||
| name = "b64-ct" | ||
| version = "0.1.0" | ||
| authors = ["Fortanix, Inc."] | ||
| license = "MPL-2.0" | ||
| edition = "2018" | ||
| description = """ | ||
| Fast and secure Base64 encoding/decoding. | ||
|
|
||
| This crate provides an implementation of Base64 encoding/decoding that is | ||
| designed to be resistant against software side-channel attacks (such as timing | ||
| & cache attacks), see the documentation for details. On certain platforms it | ||
| also uses SIMD making it very fast. This makes it suitable for e.g. decoding | ||
| cryptographic private keys in PEM format. | ||
|
|
||
| The API is very similar to the base64 implementation in the old rustc-serialize | ||
| crate, making it easy to use in existing projects. | ||
| """ | ||
| repository = "https://github.com/fortanix/b64-ct/" | ||
| keywords = ["base64", "constant-time"] | ||
| categories = ["cryptography", "encoding", "no-std"] | ||
| readme = "README.md" | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [] | ||
| nightly = [] # Used only for testing | ||
|
|
||
| [dev-dependencies] | ||
| rand = "0.6" | ||
| paste = "0.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| status = [ | ||
| "continuous-integration/travis-ci/push", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* Copyright (c) Fortanix, Inc. | ||
| * | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| use core::arch::x86_64::*; | ||
|
|
||
| #[rustfmt::skip] | ||
| pub(crate) unsafe fn dup_mm_setr_epi8(e: [i8; 16]) -> __m256i { | ||
| _mm256_setr_epi8( | ||
| e[0x0], e[0x1], e[0x2], e[0x3], e[0x4], e[0x5], e[0x6], e[0x7], | ||
| e[0x8], e[0x9], e[0xa], e[0xb], e[0xc], e[0xd], e[0xe], e[0xf], | ||
| e[0x0], e[0x1], e[0x2], e[0x3], e[0x4], e[0x5], e[0x6], e[0x7], | ||
| e[0x8], e[0x9], e[0xa], e[0xb], e[0xc], e[0xd], e[0xe], e[0xf], | ||
| ) | ||
| } | ||
|
|
||
| #[rustfmt::skip] | ||
| pub(crate) unsafe fn dup_mm_setr_epu8(e: [u8; 16]) -> __m256i { | ||
| _mm256_setr_epi8( | ||
| e[0x0] as _, e[0x1] as _, e[0x2] as _, e[0x3] as _, e[0x4] as _, e[0x5] as _, e[0x6] as _, e[0x7] as _, | ||
| e[0x8] as _, e[0x9] as _, e[0xa] as _, e[0xb] as _, e[0xc] as _, e[0xd] as _, e[0xe] as _, e[0xf] as _, | ||
| e[0x0] as _, e[0x1] as _, e[0x2] as _, e[0x3] as _, e[0x4] as _, e[0x5] as _, e[0x6] as _, e[0x7] as _, | ||
| e[0x8] as _, e[0x9] as _, e[0xa] as _, e[0xb] as _, e[0xc] as _, e[0xd] as _, e[0xe] as _, e[0xf] as _, | ||
| ) | ||
| } | ||
|
|
||
| pub(crate) unsafe fn _mm256_not_si256(i: __m256i) -> __m256i { | ||
| _mm256_xor_si256(i, _mm256_set1_epi8(!0)) | ||
| } | ||
|
|
||
| pub(crate) unsafe fn array_as_m256i(v: [u8; 32]) -> __m256i { | ||
| core::mem::transmute(v) | ||
jack-fortanix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| pub(crate) unsafe fn m256i_as_array(v: __m256i) -> [u8; 32] { | ||
| core::mem::transmute(v) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.