encryption

package
v0.0.0-...-3a25cc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MangleIndexNormalKey0 = iota
	MangleIndexNormalKey1
	MangleIndexNormalKey2
	MangleIndexNormalKey3
	MangleIndexNormalKey4
	MangleIndexNormalKey5
	MangleIndexNormalKey6
	MangleIndexNormalKey7

	MangleIndexAlternateKey0
	MangleIndexAlternateKey1
	MangleIndexAlternateKey2
	MangleIndexAlternateKey3
	MangleIndexAlternateKey4
	MangleIndexAlternateKey5
	MangleIndexAlternateKey6
	MangleIndexAlternateKey7

	MangleIndexDeviceKey = 0xffff
)
View Source
const (
	OuterMangleKeyOffsetDefault  = 0
	OuterMangleKeyOffsetFlash    = OuterMangleKeyOffsetDefault
	OuterMangleKeyOffsetDeviceId = 1
	OuterMangleKeyOffsetMemory   = 6
)
View Source
const BorlandRandAddend uint32 = 1
View Source
const BorlandRandModulus = 0xFFFFFFFF
View Source
const BorlandRandMultiplier uint32 = 0x015A4E35

BorlandRandMultiplier 22695477

View Source
const BorlandRandMultiplierInverse uint32 = 0x2925141D

BorlandRandMultiplierInverse Calculated using math.ModularMultiplicativeInverseFixed(uint32(BorlandRandMultiplier))

View Source
const BorlandRandOutputMask uint32 = 0x7FFF
View Source
const BorlandRandOutputShift = 16
View Source
const EncryptedBlockCRC1Offset = EncryptedBlockMangleKeyOffset + MangleKeyDataSize
View Source
const EncryptedBlockCRC2Offset = EncryptedBlockCRC1Offset + 4
View Source
const EncryptedBlockKeySize = 512
View Source
const EncryptedBlockMangleIndexOffset = 0
View Source
const EncryptedBlockMangleKeyOffset = EncryptedBlockMangleIndexOffset + 2
View Source
const EncryptedBlockPaddingKeyOffset = EncryptedBlockCRC2Offset + 4
View Source
const JavaRandAddend uint64 = 11
View Source
const JavaRandModulus = (1 << 48) - 1
View Source
const JavaRandMultiplier uint64 = 0x5DEECE66D

JavaRandMultiplier 25214903917

View Source
const JavaRandMultiplierInverse uint64 = 0xdfe05bcb1365

JavaRandMultiplierInverse Calculated using math.ModularMultiplicativeInverseBits(uint64(JavaRandMultiplier), 48)

View Source
const JavaRandOutputMask uint64 = 0xFFFF
View Source
const JavaRandOutputShift = 48 - 16
View Source
const MangleKeyBlockSize = 8
View Source
const MangleKeyDataSize = 4 * 4
View Source
const MangleKeyRounds = 48

Variables

View Source
var AlternateMangleTable = MangleKeyTable{
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
	{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
}
View Source
var HardcodedMangleTable = MangleKeyTable{

	{0x6f, 0xc0, 0x39, 0x05, 0x01, 0x58, 0x23, 0x3a, 0x80, 0xda, 0xb4, 0x1b, 0x65, 0x6a, 0x91, 0x44},

	{0x35, 0xcb, 0x01, 0x5b, 0xfb, 0xa4, 0x98, 0xb4, 0x82, 0x6d, 0x48, 0xe9, 0x10, 0x50, 0x94, 0xf4},
	{0xec, 0xbc, 0xba, 0xe8, 0xf8, 0x3d, 0xa7, 0x2a, 0x9c, 0xf7, 0xf9, 0x4c, 0xe7, 0x73, 0x6d, 0x88},
	{0x03, 0x35, 0x48, 0x25, 0xaf, 0xa8, 0xa0, 0xb1, 0xb2, 0x45, 0xa7, 0x24, 0x39, 0x13, 0xe2, 0xf5},
	{0x88, 0x90, 0xd8, 0x42, 0xaf, 0x79, 0xa3, 0x37, 0xe0, 0x89, 0x26, 0x42, 0xe9, 0x39, 0x62, 0x63},
	{0xf0, 0x61, 0xd0, 0xab, 0x79, 0x05, 0x71, 0x7f, 0x51, 0x6b, 0x62, 0xbd, 0x15, 0x2c, 0xf2, 0x2a},

	{0x06, 0xbc, 0x41, 0xb3, 0x74, 0x46, 0x6e, 0x6e, 0x01, 0x7b, 0xeb, 0xb3, 0x32, 0x5b, 0x96, 0xf1},
	{0x6f, 0x3e, 0xf3, 0x52, 0xf9, 0xa2, 0x69, 0x4d, 0xc4, 0x77, 0xab, 0x77, 0x08, 0x45, 0x8f, 0x46},
}

Functions

func BorlandRand

func BorlandRand(seed uint32) (newSeed uint32, output uint16)

BorlandRand Borland C++ rand()

func BorlandRandNextSeed

func BorlandRandNextSeed(seed uint32) uint32

func BorlandRandOutput

func BorlandRandOutput(seed uint32) uint16

func BorlandRandPreviousSeed

func BorlandRandPreviousSeed(seed uint32) uint32

func BorlandRandXORBytes

func BorlandRandXORBytes(src, dst []byte, seed uint32) (newSeed uint32)

func BorlandRandXORInPlace

func BorlandRandXORInPlace(data []byte, seed uint32) (newSeed uint32)

func BorlandRandXORUint32

func BorlandRandXORUint32(value, seed uint32) (newValue, newSeed uint32)

func BruteforceBorlandSeed

func BruteforceBorlandSeed(b EncryptedBlock, material KeyMaterial) ([]uint32, error)

func BruteforceBorlandSeedBytes

func BruteforceBorlandSeedBytes(b EncryptedBlock, material KeyMaterial) ([]uint32, error)

func DecryptDeviceCode

func DecryptDeviceCode(deviceId DeviceId, code []byte) []byte

DecryptDeviceCode Decrypts code specifically encrypted to only work on a specific device id

func EncryptDeviceCode

func EncryptDeviceCode(deviceId DeviceId, code []byte) []byte

EncryptDeviceCode Encrypt code specifically encrypted to only work on a specific device id

func IsKeyBorlandSeedLikely

func IsKeyBorlandSeedLikely(b EncryptedBlock, material KeyMaterial) bool

IsKeyBorlandSeedLikely The generator used on BorlandRand does not set the highest bit, as such it can be detected

func JavaRand

func JavaRand(seed uint64) (newSeed uint64, output uint16)

JavaRand Borland java.util.Random

func JavaRandNextSeed

func JavaRandNextSeed(seed uint64) uint64

func JavaRandOutput

func JavaRandOutput(seed uint64) uint16

func JavaRandOutputBits

func JavaRandOutputBits(seed uint64, bits int) uint64

func JavaRandPreviousSeed

func JavaRandPreviousSeed(seed uint64) uint64

Types

type BorlandRandByteKeyGenerator

type BorlandRandByteKeyGenerator uint32

BorlandRandByteKeyGenerator Generates random numbers with its value as current seed

func (*BorlandRandByteKeyGenerator) FillKeyBlock

func (g *BorlandRandByteKeyGenerator) FillKeyBlock(data []byte)

func (*BorlandRandByteKeyGenerator) MangleIndex

func (g *BorlandRandByteKeyGenerator) MangleIndex() uint32

type BorlandRandKeyGenerator

type BorlandRandKeyGenerator uint32

BorlandRandKeyGenerator Generates random numbers with its value as current seed

func (*BorlandRandKeyGenerator) FillKeyBlock

func (g *BorlandRandKeyGenerator) FillKeyBlock(data []byte)

func (*BorlandRandKeyGenerator) MangleIndex

func (g *BorlandRandKeyGenerator) MangleIndex() uint32

type DeviceId

type DeviceId [3]uint32

type EncryptedBlock

type EncryptedBlock []byte

func NewEncryptedBlock

func NewEncryptedBlock(size int) EncryptedBlock

func (EncryptedBlock) CRC

func (b EncryptedBlock) CRC() (crc1, crc2 uint32)

func (EncryptedBlock) DataBlock

func (b EncryptedBlock) DataBlock() []byte

func (EncryptedBlock) Decrypt

func (b EncryptedBlock) Decrypt(material KeyMaterial, verifyCrc bool) (err error)

func (EncryptedBlock) Encrypt

func (b EncryptedBlock) Encrypt(material KeyMaterial) error

func (EncryptedBlock) KeyBlock

func (b EncryptedBlock) KeyBlock() []byte

func (EncryptedBlock) MangleIndex

func (b EncryptedBlock) MangleIndex() uint32

func (EncryptedBlock) MangleKey

func (b EncryptedBlock) MangleKey() MangleKeyData

func (EncryptedBlock) MangleKeyBlock

func (b EncryptedBlock) MangleKeyBlock() []byte

MangleKeyBlock Includes inner MangleKeyData and CRC1, CRC2

func (EncryptedBlock) Reset

func (b EncryptedBlock) Reset()

type KeyGenerator

type KeyGenerator interface {
	FillKeyBlock(data []byte)
	MangleIndex() uint32
}

func NewMangleIndexGeneratorWrapper

func NewMangleIndexGeneratorWrapper(generator KeyGenerator, mangleIndex uint32) KeyGenerator

func NewMangleIndexOffsetGeneratorWrapper

func NewMangleIndexOffsetGeneratorWrapper(generator KeyGenerator, offset uint32) KeyGenerator

type KeyMaterial

type KeyMaterial struct {
	// Generator Random source to generate the inline material
	Generator         KeyGenerator
	OuterKeyOffset    OuterMangleKeyOffset
	DeviceKey         *MangleKeyData
	AlternateKeyTable *MangleKeyTable

	// CRC method to calculate CRC. If none is set, default is used.
	CRC func(data []byte) uint32
}

func NewFlashKeyMaterial

func NewFlashKeyMaterial(generator KeyGenerator) KeyMaterial

func NewMemoryKeyMaterial

func NewMemoryKeyMaterial(generator KeyGenerator) KeyMaterial

type MangleKeyData

type MangleKeyData [MangleKeyDataSize]byte

MangleKeyData Key entries of 128-bit length

func DeviceMangleKeyOffset0

func DeviceMangleKeyOffset0(deviceId DeviceId) *MangleKeyData

func DeviceMangleKeyOffset6

func DeviceMangleKeyOffset6(deviceId DeviceId) *MangleKeyData

func (MangleKeyData) Decrypt

func (d MangleKeyData) Decrypt(data []byte)

func (MangleKeyData) DecryptBlock

func (d MangleKeyData) DecryptBlock(block uint64) uint64

func (MangleKeyData) Encrypt

func (d MangleKeyData) Encrypt(data []byte)

func (MangleKeyData) EncryptBlock

func (d MangleKeyData) EncryptBlock(block uint64) uint64

func (MangleKeyData) RoundKey

func (d MangleKeyData) RoundKey(round int) uint32

type MangleKeyTable

type MangleKeyTable [8]MangleKeyData

type OuterMangleKeyOffset

type OuterMangleKeyOffset int

type SecureRandomKeyGenerator

type SecureRandomKeyGenerator struct{}

SecureRandomKeyGenerator Generates random numbers using the system secure random number generator

func (*SecureRandomKeyGenerator) FillKeyBlock

func (g *SecureRandomKeyGenerator) FillKeyBlock(data []byte)

func (*SecureRandomKeyGenerator) MangleIndex

func (g *SecureRandomKeyGenerator) MangleIndex() uint32

type ZeroKeyGenerator

type ZeroKeyGenerator struct{}

ZeroKeyGenerator Always outputs zero

func (*ZeroKeyGenerator) FillKeyBlock

func (g *ZeroKeyGenerator) FillKeyBlock(data []byte)

func (*ZeroKeyGenerator) MangleIndex

func (g *ZeroKeyGenerator) MangleIndex() uint32

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL