processingunit.h 1.63 KB
Newer Older
Ondrej Mosnáček's avatar
Ondrej Mosnáček committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
#ifndef ARGON2_CUDA_PROCESSINGUNIT_H
#define ARGON2_CUDA_PROCESSINGUNIT_H

#include <memory>

#include "programcontext.h"
#include "argon2-gpu-common/argon2params.h"

namespace argon2 {
namespace cuda {

class ProcessingUnit
{
private:
    const ProgramContext *programContext;
    const Argon2Params *params;
    const Device *device;

    std::size_t batchSize;
    std::size_t memorySize;

    bool bySegment;

    cudaStream_t stream;
    void *memoryBuffer;

public:
    class PasswordWriter
    {
    private:
        const Argon2Params *params;
        Type type;
        Version version;
        std::uint8_t *dest;

    public:
        PasswordWriter(ProcessingUnit &parent, std::size_t index = 0);

        void moveForward(std::size_t offset);
        void moveBackwards(std::size_t offset);

        void setPassword(const void *pw, std::size_t pwSize) const;
    };

    class HashReader
    {
    private:
        const Argon2Params *params;
        const std::uint8_t *src;
        std::unique_ptr<uint8_t[]> buffer;

    public:
        HashReader(ProcessingUnit &parent, std::size_t index = 0);

        void moveForward(std::size_t offset);
        void moveBackwards(std::size_t offset);

        const void *getHash() const;
    };

    std::size_t getBatchSize() const { return batchSize; }

    ProcessingUnit(
            const ProgramContext *programContext, const Argon2Params *params,
            const Device *device, std::size_t batchSize,
            bool bySegment = true);
    ~ProcessingUnit();

    void beginProcessing();
    void endProcessing();
};

} // namespace cuda
} // namespace argon2

#endif // ARGON2_CUDA_PROCESSINGUNIT_H