processingunit.h 1.57 KB
Newer Older
Ondrej Mosnáček's avatar
Ondrej Mosnáček committed
1 2 3 4 5 6
#ifndef ARGON2_CUDA_PROCESSINGUNIT_H
#define ARGON2_CUDA_PROCESSINGUNIT_H

#include <memory>

#include "programcontext.h"
7
#include "kernels.h"
Ondrej Mosnáček's avatar
Ondrej Mosnáček committed
8 9 10 11 12 13 14 15 16 17 18 19
#include "argon2-gpu-common/argon2params.h"

namespace argon2 {
namespace cuda {

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

20 21
    Argon2KernelRunner runner;
    uint32_t bestBlockSize;
Ondrej Mosnáček's avatar
Ondrej Mosnáček committed
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

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;
    };

57
    std::size_t getBatchSize() const { return runner.getBatchSize(); }
Ondrej Mosnáček's avatar
Ondrej Mosnáček committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71

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

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

} // namespace cuda
} // namespace argon2

#endif // ARGON2_CUDA_PROCESSINGUNIT_H