Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tahoe-CHK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
PrivateStorage
Tahoe-CHK
Commits
b4482ac3
Commit
b4482ac3
authored
Sep 29, 2023
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
Un-hard-code the block size and related minor tweaks
parent
ac7beaa2
No related branches found
No related tags found
1 merge request
!55
Re-instate lazy encryption / decryption
Pipeline
#5382
passed
Sep 29, 2023
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Tahoe/CHK/Encrypt.hs
+14
-7
14 additions, 7 deletions
src/Tahoe/CHK/Encrypt.hs
with
14 additions
and
7 deletions
src/Tahoe/CHK/Encrypt.hs
+
14
−
7
View file @
b4482ac3
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
-- | Support the encryption requirements of CHK.
-- | Support the encryption requirements of CHK.
module
Tahoe.CHK.Encrypt
(
encrypt
,
encryptLazy
,
decrypt
,
decryptLazy
)
where
module
Tahoe.CHK.Encrypt
(
encrypt
,
encryptLazy
,
decrypt
,
decryptLazy
)
where
import
Crypto.Cipher.Types
(
BlockCipher
(
ctrCombine
),
ivAdd
,
nullIV
)
import
Crypto.Cipher.Types
(
BlockCipher
(
blockSize
,
ctrCombine
),
ivAdd
,
nullIV
)
import
Data.ByteArray
(
ByteArray
)
import
Data.ByteArray
(
ByteArray
)
import
qualified
Data.ByteString.Lazy
as
LBS
import
qualified
Data.ByteString.Lazy
as
LBS
import
Data.List
(
unfoldr
)
import
Data.List
(
unfoldr
)
...
@@ -18,19 +21,23 @@ encrypt :: (BlockCipher cipher, ByteArray ba) => cipher -> ba -> ba
...
@@ -18,19 +21,23 @@ encrypt :: (BlockCipher cipher, ByteArray ba) => cipher -> ba -> ba
encrypt
key
=
ctrCombine
key
nullIV
encrypt
key
=
ctrCombine
key
nullIV
-- | Like encrypt but operate on lazy bytestrings.
-- | Like encrypt but operate on lazy bytestrings.
encryptLazy
::
BlockCipher
cipher
=>
cipher
->
LBS
.
ByteString
->
LBS
.
ByteString
encryptLazy
::
forall
cipher
.
BlockCipher
cipher
=>
cipher
->
LBS
.
ByteString
->
LBS
.
ByteString
encryptLazy
cipher
lbs
=
LBS
.
concat
.
(
LBS
.
fromStrict
<$>
)
$
zipWith
(
ctrCombine
cipher
)
ivs
blocks
encryptLazy
cipher
lbs
=
LBS
.
concat
.
(
LBS
.
fromStrict
<$>
)
$
zipWith
(
ctrCombine
cipher
)
ivs
blocks
where
where
-- The underlying encryption function works on strict bytes. Here's the
-- The underlying encryption function works on strict bytes. Here's the
-- number of bytes to feed to it (that is, to make strict) at a time.
-- number of *blocks* to feed to it (that is, to make strict) at a time.
workingBlockSize
::
Int
-- This value here is a magic number that is meant to represent a good
workingBlockSize
=
1024
*
64
-- compromise between performance and number of bytes forced at one time.
workingBlocks
=
1024
*
16
-- The size of a block is determined by the cipher.
workingBytes
=
workingBlocks
*
blockSize
@
cipher
undefined
ivs
=
iterate
(`
ivAdd
`
(
workingBlock
Size
`
div
`
16
)
)
nullIV
ivs
=
iterate
(`
ivAdd
`
workingBlock
s
)
nullIV
blocks
=
LBS
.
toStrict
<$>
unfoldr
takeChunk
lbs
blocks
=
LBS
.
toStrict
<$>
unfoldr
takeChunk
lbs
takeChunk
""
=
Nothing
takeChunk
""
=
Nothing
takeChunk
xs
=
Just
.
LBS
.
splitAt
(
fromIntegral
workingB
lockSize
)
$
xs
takeChunk
xs
=
Just
.
LBS
.
splitAt
(
fromIntegral
workingB
ytes
)
$
xs
-- | AES128-CTR decrypt a byte string in the manner used by CHK.
-- | AES128-CTR decrypt a byte string in the manner used by CHK.
decrypt
::
(
BlockCipher
cipher
,
ByteArray
ba
)
=>
cipher
->
ba
->
ba
decrypt
::
(
BlockCipher
cipher
,
ByteArray
ba
)
=>
cipher
->
ba
->
ba
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment