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
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
0a749a33
Commit
0a749a33
authored
1 year ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
wip - adding BlockCipher to replace the other uses
parent
6bfeb84b
No related branches found
No related tags found
1 merge request
!54
Switch away from cipher-aes128
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Tahoe/CHK/Cipher.hs
+14
-1
14 additions, 1 deletion
src/Tahoe/CHK/Cipher.hs
src/Tahoe/CHK/Upload.hs
+12
-4
12 additions, 4 deletions
src/Tahoe/CHK/Upload.hs
with
26 additions
and
5 deletions
src/Tahoe/CHK/Cipher.hs
+
14
−
1
View file @
0a749a33
...
...
@@ -10,9 +10,10 @@ module Tahoe.CHK.Cipher (
)
where
import
Control.DeepSeq
(
NFData
)
import
Crypto.Cipher.Types
(
Cipher
(
..
))
import
Crypto.Cipher.Types
(
BlockCipher
(
..
),
Cipher
(
..
))
import
Data.ByteArray
(
ScrubbedBytes
)
import
qualified
Data.ByteArray
as
BA
import
Data.Coerce
(
coerce
)
import
GHC.Generics
(
Generic
)
data
Key
cipher
=
Key
{
keyBytes
::
ScrubbedBytes
,
keyCipher
::
cipher
}
...
...
@@ -25,6 +26,18 @@ instance forall cipher. Cipher cipher => Cipher (Key cipher) where
cipherName
_
=
cipherName
@
cipher
undefined
cipherKeySize
_
=
cipherKeySize
@
cipher
undefined
instance
forall
cipher
.
BlockCipher
cipher
=>
BlockCipher
(
Key
cipher
)
where
blockSize
_
=
blockSize
@
cipher
undefined
ecbEncrypt
=
ecbEncrypt
.
keyCipher
ecbDecrypt
=
ecbDecrypt
.
keyCipher
cbcEncrypt
(
Key
_
cipher
)
iv
=
cbcEncrypt
cipher
(
coerce
iv
)
cbcDecrypt
(
Key
_
cipher
)
iv
=
cbcDecrypt
cipher
(
coerce
iv
)
cfbEncrypt
(
Key
_
cipher
)
iv
=
cfbEncrypt
cipher
(
coerce
iv
)
cfbDecrypt
(
Key
_
cipher
)
iv
=
cfbDecrypt
cipher
(
coerce
iv
)
ctrCombine
(
Key
_
cipher
)
iv
=
ctrCombine
cipher
(
coerce
iv
)
aeadInit
mode
(
Key
_
cipher
)
iv
=
xxx
instance
BA
.
ByteArrayAccess
(
Key
cipher
)
where
length
(
Key
ba
_
)
=
BA
.
length
ba
withByteArray
(
Key
ba
_
)
=
BA
.
withByteArray
ba
This diff is collapsed.
Click to expand it.
src/Tahoe/CHK/Upload.hs
+
12
−
4
View file @
0a749a33
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
...
...
@@ -35,6 +36,7 @@ import Data.IORef (
)
import
qualified
Data.Binary
as
Binary
import
Data.ByteArray
(
ScrubbedBytes
)
import
qualified
Data.ByteString
as
B
import
qualified
Data.ByteString.Lazy
as
BL
...
...
@@ -60,8 +62,8 @@ import System.IO (
)
import
Crypto.Cipher.AES
(
AES128
)
import
Crypto.Cipher.Types
(
BlockCipher
,
Cipher
(
cipherInit
))
import
Crypto.Random
(
getRandomBytes
)
import
Crypto.Cipher.Types
(
BlockCipher
,
Cipher
(
cipherInit
,
cipherKeySize
),
KeySizeSpecifier
(
..
))
import
"cryptonite"
Crypto.Random
(
getRandomBytes
)
import
Tahoe.CHK.Cipher
(
Key
)
import
Tahoe.CHK.Crypto
(
...
...
@@ -339,8 +341,14 @@ getConvergentKey secret params content =
buildKeyIO
::
forall
cipher
.
BlockCipher
cipher
=>
IO
(
Key
cipher
)
buildKeyIO
=
do
keyBytes
<-
getRandomBytes
(
cipherKeySize
@
cipher
undefined
)
fromJust
.
maybeCryptoError
.
cipherInit
$
keyBytes
keyBytes
<-
getRandomBytes
@
IO
@
ScrubbedBytes
keySize
pure
.
fromJust
.
maybeCryptoError
.
cipherInit
$
keyBytes
where
keySize
=
case
cipherKeySize
@
cipher
undefined
of
KeySizeRange
_
high
->
high
KeySizeEnum
[]
->
error
"no key sizes!"
KeySizeEnum
(
s
:
_
)
->
s
KeySizeFixed
s
->
s
-- Create an uploadable with a random key.
filesystemUploadableRandomConvergence
::
FilePath
->
Parameters
->
IO
Uploadable
...
...
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