spring-projects / spring-projects/spring-security

SCryptPasswordEncoder Key Length Issue

Open
#4,788 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: crypto type: enhancement
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Summary

During the matches operation, SCryptPasswordEncoder retains the instance keyLength rather than the target digest keyLength. It makes it very difficult to verify non-homogenous digests with different key lengths.

Why is that? A security consideration?

Actual Behavior

SCryptPasswordEncoder matches operation fails if instance keyLength differs from target digest key length.

Expected Behavior

SCryptPasswordEncoder matches operation ought to use the target digest key length.

Configuration

SCryptPasswordEncoder instance keyLength differs from target digest key length.

Version

4.2.3.RELEASE

Sample

Simple example prints true

SCryptPasswordEncoder encoder = new SCryptPasswordEncoder(8192, 16, 1, 32, 32);
String raw = "password";
String digest = encoder.encode(raw);
System.out.println(encoder.matches(raw, digest));

Instance parameters differ from digest parameters, except key length - prints true

SCryptPasswordEncoder encoder = new SCryptPasswordEncoder(8192, 16, 1, 32, 32);
SCryptPasswordEncoder tester = new SCryptPasswordEncoder(1024, 8, 1, 32, 24);
String raw = "password";
String digest = encoder.encode(raw);
System.out.println(tester.matches(raw, digest));

Only the key length differs - prints false

SCryptPasswordEncoder encoder = new SCryptPasswordEncoder(8192, 16, 1, 32, 32);
SCryptPasswordEncoder tester = new SCryptPasswordEncoder(8192, 16, 1, 24, 32);
String raw = "password";
String digest = encoder.encode(raw);
System.out.println(tester.matches(raw, digest));

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SCryptPasswordEncoder matches operation and compare its handling of the instance keyLength with the key length encoded in the target digest. Reproduce the three Java examples from the issue, then confirm that matching succeeds when only the instance and digest key lengths differ.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.