Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
hash / hash-pbkdf2-sha256OpenRuns on Liberas

PBKDF2-HMAC-SHA256

PBKDF2 (RFC 8018, section 5.2) with HMAC-SHA256 as the PRF: length bytes derived from password and salt (bytes, base64 in JSON) with the given iteration count, lowercase hex. iterations must be 1 to 100,000, length 1 to 1,024, and iterations × ceil(length / 32) at most 500,000 (each 32-byte block costs a full run of iterations); otherwise an error, checked in that order, and nothing is derived.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init hash-pbkdf2-sha256 --lang rust
cd hash-pbkdf2-sha256 && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
hash-pbkdf2-sha256.wit
package root:component;

world root {
  export liberas:hash/derive@0.1.0;
}
package liberas:hash@0.1.0 {
  interface derive {
    derive: func(password: list<u8>, salt: list<u8>, iterations: u32, length: u32) -> result<string, string>;
  }
}
Test vectors15›
hash-pbkdf2-sha256.cases.json
[
  {
    "args": {
      "salt": "c2FsdA==",
      "length": 32,
      "password": "cGFzc3dvcmQ=",
      "iterations": 1
    }
  },
  {
    "args": {
      "salt": "c2FsdA==",
      "length": 32,
      "password": "cGFzc3dvcmQ=",
      "iterations": 2
    }
  },
  {
    "args": {
      "salt": "c2FsdA==",
      "length": 32,
      "password": "cGFzc3dvcmQ=",
      "iterations": 4096
    }
  },
  {
    "args": {
      "salt": "c2FsdFNBTFRzYWx0U0FMVHNhbHRTQUxUc2FsdFNBTFRzYWx0",
      "length": 40,
      "password": "cGFzc3dvcmRQQVNTV09SRHBhc3N3b3Jk",
      "iterations": 4096
    }
  },
  {
    "args": {
      "salt": "c2EAbHQ=",
      "length": 16,
      "password": "cGFzcwB3b3Jk",
      "iterations": 4096
    }
  },
  {
    "args": {
      "salt": "",
      "length": 1,
      "password": "",
      "iterations": 1
    }
  },
  {
    "args": {
      "salt": "cw==",
      "length": 1024,
      "password": "cA==",
      "iterations": 10
    }
  },
  {
    "args": {
      "salt": "AAECAwQFBgcICQoLDA0ODw==",
      "length": 64,
      "password": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiYw==",
      "iterations": 1000
    }
  },
  {
    "args": {
      "salt": "eQ==",
      "length": 32,
      "password": "eA==",
      "iterations": 0
    }
  },
  {
    "args": {
      "salt": "eQ==",
      "length": 32,
      "password": "eA==",
      "iterations": 100001
    }
  },
  {
    "args": {
      "salt": "eQ==",
      "length": 0,
      "password": "eA==",
      "iterations": 1
    }
  },
  {
    "args": {
      "salt": "eQ==",
      "length": 1025,
      "password": "eA==",
      "iterations": 1
    }
  },
  {
    "args": {
      "salt": "eQ==",
      "length": 64,
      "password": "eA==",
      "iterations": 100000
    }
  },
  {
    "args": {
      "salt": "eQ==",
      "length": 200,
      "password": "eA==",
      "iterations": 100000
    }
  },
  {
    "args": {
      "salt": "eQ==",
      "length": 0,
      "password": "eA==",
      "iterations": 0
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 15 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 10,000,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.