Skip to content

Commit

Permalink
Result TAG can fetched after encrypt final
Browse files Browse the repository at this point in the history
IB-7877

Signed-off-by: Raul Metsma <raul@metsma.ee>
  • Loading branch information
metsma committed Nov 9, 2023
1 parent 7e67739 commit 3931a95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 5 additions & 1 deletion client/CDoc2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,16 @@ bool CDoc2::save(const QString &path)
file.remove();
return false;
}
file.write(enc.resultTAG());
if(!enc.result())
{
file.remove();
return false;
}
QByteArray tag = enc.tag();
#ifndef NDEBUG
qDebug() << "tag" << tag.toHex();
#endif
file.write(tag);
return true;
}

Expand Down
15 changes: 10 additions & 5 deletions client/Crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ bool Crypto::Cipher::result() const
return true;
}

QByteArray Crypto::Cipher::resultTAG() const
QByteArray Crypto::Cipher::tag() const
{
QByteArray result(EVP_CIPHER_CTX_block_size(ctx.get()), 0);
if(isError(EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_GET_TAG, int(result.size()), result.data())))
result.clear();
return result;
if(QByteArray result(tagLen(), 0);
!isError(EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_GET_TAG, int(result.size()), result.data())))
return result;
return {};
}

int Crypto::Cipher::tagLen()
{
return 16;
}

QByteArray Crypto::aes_wrap(const QByteArray &key, const QByteArray &data, bool encrypt)
Expand Down
3 changes: 2 additions & 1 deletion client/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class Crypto
QByteArray update(const QByteArray &data) const;
bool update(char *data, int size) const;
bool result() const;
QByteArray resultTAG() const;
QByteArray tag() const;
static int tagLen();
};

static QByteArray aes_wrap(const QByteArray &key, const QByteArray &data, bool encrypt);
Expand Down

0 comments on commit 3931a95

Please sign in to comment.