Skip to content

Salsa20: Set initial block counter #908

Description

@smiRaphi

I would like the ability to be able to set the initial block counter to something other than 0 as I'm working on an extractor for this project here and that sets the block counter to a random value like 0xde7a8b6883eeed8d where encrypting/decrypting dummy data isn't feasible.

Currently this is my workaround which works but is pretty hacky:

import ctypes
from Cryptodome.Cipher import Salsa20
bc = int.from_bytes(nonce[8:16],'little')
ctx = Salsa20.new(key,nonce[:8])
pctx = ctypes.cast(ctx._state.get(),ctypes.POINTER(ctypes.c_uint32))
pctx[8],pctx[9] = bc & 0xFFFFFFFF,(bc >> 32) & 0xFFFFFFFF
o = ctx.decrypt(i)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions