Skip to content

Commit

Permalink
docs, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DV committed Oct 20, 2014
1 parent feeaebc commit 2aa5b57
Show file tree
Hide file tree
Showing 21 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions aes_cbc_hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
)

// AES CBC with HMAC authenticated encryption algorithm implementation
type AesCbcHmac struct{
keySizeBits int
}
Expand Down
1 change: 1 addition & 0 deletions aes_gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"jose2go/arrays"
)

// AES GCM authenticated encryption algorithm implementation
type AesGcm struct{
keySizeBits int
}
Expand Down
1 change: 1 addition & 0 deletions aes_gcm_kw.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func init() {
RegisterJwa(&AesGcmKW{ keySizeBits: 256})
}

// AES GCM Key Wrap key management algorithm implementation
type AesGcmKW struct {
keySizeBits int
}
Expand Down
1 change: 1 addition & 0 deletions aeskw.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func init() {
RegisterJwa(&AesKW{ keySizeBits: 256})
}

// AES Key Wrap key management algorithm implementation
type AesKW struct {
keySizeBits int
}
Expand Down
1 change: 1 addition & 0 deletions deflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func init() {
RegisterJwc(new(Deflate))
}

// Deflate compression algorithm implementation
type Deflate struct {}

func (alg *Deflate) Name() string {
Expand Down
1 change: 1 addition & 0 deletions direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ func init() {
RegisterJwa(new(Direct))
}

// Direct (pre-shared) key management algorithm implementation
type Direct struct{
}

Expand Down
1 change: 1 addition & 0 deletions ecdh.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func init() {
RegisterJwa(&Ecdh{directAgreement:true})
}

// Elliptic curve Diffie–Hellman key management (key agreement) algorithm implementation
type Ecdh struct{
directAgreement bool
}
Expand Down
1 change: 1 addition & 0 deletions ecdh_aeskw.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ func init() {
RegisterJwa(&EcdhAesKW{ keySizeBits: 256, aesKW: &AesKW{ keySizeBits: 256}, ecdh: &Ecdh{directAgreement:false}})
}

// Elliptic curve Diffie–Hellman with AES Key Wrap key management algorithm implementation
type EcdhAesKW struct{
keySizeBits int
aesKW JwaAlgorithm
Expand Down
7 changes: 4 additions & 3 deletions ecdsa_using_sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ func init() {
RegisterJws(&EcdsaUsingSha{keySizeBits: 521, hashSizeBits: 512})
}

// ECDSA signing algorithm implementation
type EcdsaUsingSha struct{
keySizeBits int
hashSizeBits int
}

func (alg *EcdsaUsingSha) Name() string {
switch alg.keySizeBits {
case 256: return "ES256"
case 384: return "ES384"
default: return "ES512"
case 256: return ES256
case 384: return ES384
default: return ES512
}
}

Expand Down
7 changes: 4 additions & 3 deletions hmac_using_sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ func init() {
RegisterJws(&HmacUsingSha{keySizeBits: 512})
}

// HMAC with SHA signing algorithm implementation
type HmacUsingSha struct{
keySizeBits int
}

func (alg *HmacUsingSha) Name() string {
switch alg.keySizeBits {
case 256: return "HS256"
case 384: return "HS384"
default: return "HS512"
case 256: return HS256
case 384: return HS384
default: return HS512
}
}

Expand Down
4 changes: 3 additions & 1 deletion kdf/nist_sp800_56a.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"jose2go/arrays"
)

// DeriveConcatKDF implements NIST SP 800-56A ConcatKDF function
// DeriveConcatKDF implements NIST SP 800-56A Concatenation Key Derivation Function. Derives
// key material of keydatalen bits size given Z (sharedSecret), OtherInfo (AlgorithmID |
// PartyUInfo | PartyVInfo | SuppPubInfo | SuppPrivInfo) and hash function
func DeriveConcatKDF(keydatalen int, sharedSecret, algId, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo []byte, h hash.Hash) []byte {

otherInfo := arrays.Concat(algId, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo)
Expand Down
5 changes: 5 additions & 0 deletions keys/ecc/ecc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//package ecc provides helpers for creating elliptic curve leys
package ecc

import (
Expand All @@ -9,6 +10,7 @@ import (
"errors"
)

// ReadPublic loads ecdsa.PublicKey from given PKCS1 X509 or PKIX blobs
func ReadPublic(raw []byte) (key *ecdsa.PublicKey,err error) {
var encoded *pem.Block

Expand Down Expand Up @@ -36,6 +38,7 @@ func ReadPublic(raw []byte) (key *ecdsa.PublicKey,err error) {
return key, nil
}

// ReadPrivate loads ecdsa.PrivateKey from given PKCS1 or PKCS8 blobs
func ReadPrivate(raw []byte) (key *ecdsa.PrivateKey,err error) {
var encoded *pem.Block

Expand All @@ -60,12 +63,14 @@ func ReadPrivate(raw []byte) (key *ecdsa.PrivateKey,err error) {
return key,nil
}

// NewPublic constructs ecdsa.PublicKey from given (X,Y)
func NewPublic(x,y []byte) (*ecdsa.PublicKey) {
return &ecdsa.PublicKey{ Curve: curve(len(x)),
X:new(big.Int).SetBytes(x),
Y:new(big.Int).SetBytes(y) }
}

// NewPrivate constructs ecdsa.PrivateKey from given (X,Y) and D
func NewPrivate(x,y,d []byte) (*ecdsa.PrivateKey) {
return &ecdsa.PrivateKey {D:new(big.Int).SetBytes(d),
PublicKey: ecdsa.PublicKey{ Curve:curve(len(x)),
Expand Down
3 changes: 3 additions & 0 deletions keys/rsa/rsa.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//package Rsa provides helpers for creating rsa leys
package Rsa

import (
Expand All @@ -7,6 +8,7 @@ import (
"errors"
)

// ReadPrivate loads rsa.PrivateKey from PKCS1 or PKCS8 blobs
func ReadPrivate(raw []byte) (key *rsa.PrivateKey,err error) {
var encoded *pem.Block

Expand All @@ -31,6 +33,7 @@ func ReadPrivate(raw []byte) (key *rsa.PrivateKey,err error) {
return key,nil
}

// ReadPublic loads rsa.PublicKey from PKIX or PKCS1 X509 blobs
func ReadPublic(raw []byte) (key *rsa.PublicKey,err error) {
var encoded *pem.Block

Expand Down
2 changes: 2 additions & 0 deletions padding/align.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// package padding provides various padding algorithms
package padding

import (
"bytes"
)

// Align left pads given byte array with zeros till it have at least bitSize length.
func Align(data []byte, bitSize int) []byte {

actual:=len(data)
Expand Down
2 changes: 2 additions & 0 deletions padding/pkcs7.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
)

// AddPkcs7 pads given byte array using pkcs7 padding schema till it has blockSize length in bytes
func AddPkcs7(data []byte, blockSize int) []byte {

var paddingCount int
Expand All @@ -15,6 +16,7 @@ func AddPkcs7(data []byte, blockSize int) []byte {
return append(data, bytes.Repeat([]byte{byte(paddingCount)}, paddingCount)...)
}

// RemovePkcs7 removes pkcs7 padding from previously padded byte array
func RemovePkcs7(padded []byte, blockSize int) []byte {

dataLen:=len(padded)
Expand Down
1 change: 1 addition & 0 deletions pbse2_hmac_aeskw.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func init() {
RegisterJwa(&Pbse2HmacAesKW{keySizeBits: 256,aesKW: &AesKW{ keySizeBits: 256}})
}

// PBSE2 with HMAC key management algorithm implementation
type Pbse2HmacAesKW struct{
keySizeBits int
aesKW JwaAlgorithm
Expand Down
3 changes: 2 additions & 1 deletion plaintext.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package jose

// Plaintext (no signing) signing algorithm implementation
type Plaintext struct{}

func init() {
RegisterJws(new(Plaintext))
}

func (alg *Plaintext) Name() string {
return "none"
return NONE
}

func (alg *Plaintext) Verify(securedInput []byte, signature []byte, key interface{}) error {
Expand Down
1 change: 1 addition & 0 deletions rsa_oaep.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"jose2go/arrays"
)

// RS-AES using OAEP key management algorithm implementation
func init() {
RegisterJwa(&RsaOaep {shaSizeBits:1})
RegisterJwa(&RsaOaep {shaSizeBits:256})
Expand Down
3 changes: 2 additions & 1 deletion rsa_pkcs1v15.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ func init() {
RegisterJwa(new(RsaPkcs1v15))
}

// RS-AES using PKCS #1 v1.5 padding key management algorithm implementation
type RsaPkcs1v15 struct{
}

func (alg *RsaPkcs1v15) Name() string {
return "RSA1_5"
return RSA1_5
}

func (alg *RsaPkcs1v15) WrapNewKey(cekSizeBits int, key interface{}, header map[string]interface{}) (cek []byte, encryptedCek []byte, err error) {
Expand Down
7 changes: 4 additions & 3 deletions rsa_using_sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ func init() {
RegisterJws(&RsaUsingSha{keySizeBits: 512})
}

// RSA using SHA signature algorithm implementation
type RsaUsingSha struct{
keySizeBits int
}

func (alg *RsaUsingSha) Name() string {
switch alg.keySizeBits {
case 256: return "RS256"
case 384: return "RS384"
default: return "RS512"
case 256: return RS256
case 384: return RS384
default: return RS512
}
}

Expand Down
7 changes: 4 additions & 3 deletions rsapss_using_sha.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ func init() {
RegisterJws(&RsaPssUsingSha{keySizeBits: 512, saltSizeBytes: 64})
}

// RSA with PSS using SHA signing algorithm implementation
type RsaPssUsingSha struct{
keySizeBits int
saltSizeBytes int
}

func (alg *RsaPssUsingSha) Name() string {
switch alg.keySizeBits {
case 256: return "PS256"
case 384: return "PS384"
default: return "PS512"
case 256: return PS256
case 384: return PS384
default: return PS512
}
}

Expand Down

0 comments on commit 2aa5b57

Please sign in to comment.