Skip to content

Misuse of PasMP Library in Parallel Loops #29

@BeRo1985

Description

@BeRo1985

Issue

I've noticed that this project misuses the PasMP library (which I am the author of) in parallel loop handling, which could lead to incorrect behavior in multithreaded operations. Specifically, the parallel loop wrappers are only processing the starting index (AFromIndex) without iterating through the full range (AFromIndex to AToIndex). Here are the corrections:

Corrections

  1. In TBlake2BP.PasMPParallelComputationWrapper:

    Current:

    procedure TBlake2BP.PasMPParallelComputationWrapper(const AJob: PPasMPJob;
      const AThreadIndex: LongInt; const ADataContainer: Pointer;
      const AFromIndex, AToIndex: TPasMPNativeInt);
    begin
      ParallelComputation(AFromIndex, ADataContainer);
    end;

    Corrected:

    procedure TBlake2BP.PasMPParallelComputationWrapper(const AJob: PPasMPJob;
      const AThreadIndex: LongInt; const ADataContainer: Pointer;
      const AFromIndex, AToIndex: TPasMPNativeInt);
    var Index: TPasMPNativeInt;
    begin
      for Index := AFromIndex to AToIndex do
        ParallelComputation(Index, ADataContainer);
    end;
  2. In TPBKDF_ScryptNotBuildInAdapter.PasMPSMixWrapper:

    Current:

    class procedure TPBKDF_ScryptNotBuildInAdapter.PasMPSMixWrapper
      (const AJob: PPasMPJob; const AThreadIndex: LongInt;
      const ADataContainer: Pointer; const AFromIndex, AToIndex: TPasMPNativeInt);
    begin
      SMix(AFromIndex, ADataContainer);
    end;

    Corrected:

    class procedure TPBKDF_ScryptNotBuildInAdapter.PasMPSMixWrapper
      (const AJob: PPasMPJob; const AThreadIndex: LongInt;
      const ADataContainer: Pointer; const AFromIndex, AToIndex: TPasMPNativeInt);
    var Index: TPasMPNativeInt;
    begin
      for Index := AFromIndex to AToIndex do
        SMix(Index, ADataContainer);
    end;
  3. In TPBKDF_Argon2NotBuildInAdapter.PasMPFillMemoryBlocksWrapper:

    Current:

    procedure TPBKDF_Argon2NotBuildInAdapter.PasMPFillMemoryBlocksWrapper
      (const AJob: PPasMPJob; const AThreadIndex: LongInt;
      const ADataContainer: Pointer; const AFromIndex, AToIndex: TPasMPNativeInt);
    begin
      PDataContainer(ADataContainer)^.Position.FLane := AFromIndex;
      FillMemoryBlocks(AFromIndex, ADataContainer);
    end;

    Corrected:

    procedure TPBKDF_Argon2NotBuildInAdapter.PasMPFillMemoryBlocksWrapper
      (const AJob: PPasMPJob; const AThreadIndex: LongInt;
      const ADataContainer: Pointer; const AFromIndex, AToIndex: TPasMPNativeInt);
    var Index: TPasMPNativeInt;
    begin
      for Index := AFromIndex to AToIndex do
      begin
        PDataContainer(ADataContainer)^.Position.FLane := Index;
        FillMemoryBlocks(Index, ADataContainer);
      end;  
    end;

Summary

These changes ensure that all indices within the given range are processed correctly, maintaining the intended parallelization behavior.

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