Skip to content

Commit

Permalink
switch to Rprintf()
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 18, 2023
1 parent 961e574 commit 19ec345
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 314 deletions.
4 changes: 2 additions & 2 deletions src/cryptography/cybozu/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ class File {
sync();
close();
} catch (std::exception& e) {
fprintf(stderr, "File:dstr:%s\n", e.what());
Rprintf("File:dstr:%s\n", e.what());
} catch (...) {
fprintf(stderr, "File:dstr:unknown\n");
Rprintf("File:dstr:unknown\n");
}
}
bool isOpen() const CYBOZU_NOEXCEPT { return hdl_ != INVALID_HANDLE_VALUE; }
Expand Down
8 changes: 4 additions & 4 deletions src/cryptography/cybozu/minixml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Attributes {
std::string tabstr(level + indentWidth, ' ');
const char *tab = tabstr.c_str();
for (Map::const_iterator i = m_.begin(), ie = m_.end(); i != ie; ++i) {
printf("%s%s=%s\n", tab, i->first.c_str(), i->second.c_str());
Rprintf("%s%s=%s\n", tab, i->first.c_str(), i->second.c_str());
}
}
void swap(Attributes& attr) CYBOZU_NOEXCEPT
Expand Down Expand Up @@ -166,10 +166,10 @@ struct Node {
{
std::string tabstr(level, ' ');
const char *tab = tabstr.c_str();
printf("%s<%s>\n", tab, name.c_str());
Rprintf("%s<%s>\n", tab, name.c_str());
if (!content.empty()) {
printf("%s[content]\n", tab);
printf("%s%s\n", tab, content.c_str());
Rprintf("%s[content]\n", tab);
Rprintf("%s%s\n", tab, content.c_str());
}
attr.put(level);
for (NodeList::const_iterator i = child.begin(), ie = child.end(); i != ie; ++i) {
Expand Down
7 changes: 4 additions & 3 deletions src/cryptography/cybozu/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma warning(disable : 4702)
#endif

#include "openxlsx2.h"
#include <string>
#include <cstring>
#include <assert.h>
Expand Down Expand Up @@ -302,11 +303,11 @@ class StringT {
*/
void dump(const char *msg = 0) const
{
if (msg) printf("%s", msg);
if (msg) Rprintf("%s", msg);
for (size_t i = 0; i < size(); i++) {
printf("%08x ", str_[i]);
Rprintf("%08x ", str_[i]);
}
printf("\n");
Rprintf("\n");
}

/**
Expand Down
84 changes: 42 additions & 42 deletions src/cryptography/msoc/include/cfb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ inline void putCompact(const T& vec)
uint32_t v = vec[j];
if (v == prev + 1 && j != n - 1) {
if (isFirst) {
printf(" ..");
Rprintf(" ..");
isFirst = false;
}
} else {
if (!isFirst && j > 1) {
printf(" %s", toStr(vec[j - 1]).c_str());
Rprintf(" %s", toStr(vec[j - 1]).c_str());
}
printf(" %s", toStr(v).c_str());
Rprintf(" %s", toStr(v).c_str());
isFirst = true;
}
prev = v;
}
putchar('\n');
Rprintf("\n");
}

struct Header {
Expand Down Expand Up @@ -271,17 +271,17 @@ struct Header {
void put() const
{
if (!isDebug()) return;
printf("version : major = %u, minor = 0x%04x\n", majorVersion, minorVersion);
printf("sectorShift = %u\n", sectorShift);
printf("numDirectorySectors = %u\n", numDirectorySectors);
printf("numFatSectors = %u\n", numFatSectors);
printf("firstDirectorySectorLocation = %u\n", firstDirectorySectorLocation);
printf("transactionSignatureNumber = %u\n", transactionSignatureNumber);
printf("firstMiniFatSectorLocation = %s\n", toStr(firstMiniFatSectorLocation).c_str());
printf("numMiniFatSectors = %u\n", numMiniFatSectors);
printf("firstDifatSectorLocation = %s\n", toStr(firstDifatSectorLocation).c_str());
printf("numDifatSectors = %u\n", numDifatSectors);
printf("difat size=%d\n", (int)difat.size());
Rprintf("version : major = %u, minor = 0x%04x\n", majorVersion, minorVersion);
Rprintf("sectorShift = %u\n", sectorShift);
Rprintf("numDirectorySectors = %u\n", numDirectorySectors);
Rprintf("numFatSectors = %u\n", numFatSectors);
Rprintf("firstDirectorySectorLocation = %u\n", firstDirectorySectorLocation);
Rprintf("transactionSignatureNumber = %u\n", transactionSignatureNumber);
Rprintf("firstMiniFatSectorLocation = %s\n", toStr(firstMiniFatSectorLocation).c_str());
Rprintf("numMiniFatSectors = %u\n", numMiniFatSectors);
Rprintf("firstDifatSectorLocation = %s\n", toStr(firstDifatSectorLocation).c_str());
Rprintf("numDifatSectors = %u\n", numDifatSectors);
Rprintf("difat size=%d\n", (int)difat.size());
putCompact(difat);
}
private:
Expand Down Expand Up @@ -451,7 +451,7 @@ struct DirectoryEntry {
startingSectorLocation = cybozu::Get32bitAsLE(data + 0x74);
streamSize = cybozu::Get64bitAsLE(data + 0x78);
if (streamSize >= uint64_t(0x100000000ULL)) {
printf("warning too large size=%lld\n", (long long)streamSize);
Rprintf("warning too large size=%lld\n", (long long)streamSize);
// clear upper 32bit if version 3
streamSize &= 0xffffffff;
}
Expand Down Expand Up @@ -525,29 +525,29 @@ struct DirectoryEntry {
void put() const
{
if (!isDebug()) return;
printf("directoryEntryName = ");
Rprintf("directoryEntryName = ");
#ifdef _WIN32
if (directoryEntryName.empty()) {
printf("<none>");
Rprintf("<none>");
} else {
printf("%S", &directoryEntryName[0]);
Rprintf("%S", &directoryEntryName[0]);
}
#else
printf("%s", toHex(reinterpret_cast<const char*>(&directoryEntryName[0]), directoryEntryNameLength).c_str());
Rprintf("%s", toHex(reinterpret_cast<const char*>(&directoryEntryName[0]), directoryEntryNameLength).c_str());
#endif
printf("(%u)\n", directoryEntryNameLength);
printf("objectType = %d(%s)\n", objectType, toStr(objectType).c_str());
printf("colorFlag = %d(%s)\n", colorFlag, toStr(colorFlag).c_str());
printf("leftSiblingId = %s, ", toStr(leftSiblingId).c_str());
printf("rightSiblingId = %s\n", toStr(rightSiblingId).c_str());
printf("childId = %s\n", toStr(childId).c_str());
printf("clsid = %s, ", toHex(clsid.c_str(), clsid.size()).c_str());
printf("stateBits = 0x%08x\n", stateBits);
printf("creation/modified Time = %s / %s\n", creationTime.toString().c_str(), modifiedTime.toString().c_str());
printf("startingSectorLocation = %s\n", toStr(startingSectorLocation).c_str());
printf("streamSize = %lld\n", (long long)streamSize);
Rprintf("(%u)\n", directoryEntryNameLength);
Rprintf("objectType = %d(%s)\n", objectType, toStr(objectType).c_str());
Rprintf("colorFlag = %d(%s)\n", colorFlag, toStr(colorFlag).c_str());
Rprintf("leftSiblingId = %s, ", toStr(leftSiblingId).c_str());
Rprintf("rightSiblingId = %s\n", toStr(rightSiblingId).c_str());
Rprintf("childId = %s\n", toStr(childId).c_str());
Rprintf("clsid = %s, ", toHex(clsid.c_str(), clsid.size()).c_str());
Rprintf("stateBits = 0x%08x\n", stateBits);
Rprintf("creation/modified Time = %s / %s\n", creationTime.toString().c_str(), modifiedTime.toString().c_str());
Rprintf("startingSectorLocation = %s\n", toStr(startingSectorLocation).c_str());
Rprintf("streamSize = %lld\n", (long long)streamSize);
if (content.empty()) {
printf("data=<empty>\n");
Rprintf("data=<empty>\n");
} else {
if (isDebug(2)) {
std::string fileName = cybozu::ToUtf8(directoryEntryName) + ".dump";
Expand All @@ -558,18 +558,18 @@ struct DirectoryEntry {
saveFile(fileName, content);
}
if (streamSize <= 256) {
printf("data=\n");
Rprintf("data=\n");
dump16(content, content.size());
} else {
printf("data=[");
Rprintf("data=[");
for (size_t i = 0; i < 5; i++) {
printf("%02x:", (uint8_t)content[i]);
Rprintf("%02x:", (uint8_t)content[i]);
}
printf(" ... ");
Rprintf(" ... ");
for (size_t i = content.size() - 5; i < content.size(); i++) {
printf("%02x:", (uint8_t)content[i]);
Rprintf("%02x:", (uint8_t)content[i]);
}
printf("]\n");
Rprintf("]\n");
}
}
}
Expand Down Expand Up @@ -761,13 +761,13 @@ struct CompoundFile {
{
if (!isDebug()) return;
header.put();
printf("FatSectors\n");
Rprintf("FatSectors\n");
fats.put();
printf("mini FatSectors\n");
Rprintf("mini FatSectors\n");
miniFats.put();
for (size_t i = 0; i < dirs.size(); i++) {
printf("----------------------------\n");
printf("DirectoryEntry %lld\n", (long long)i);
Rprintf("----------------------------\n");
Rprintf("DirectoryEntry %lld\n", (long long)i);
dirs[i].put();
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/cryptography/msoc/include/crypto_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Xbyak::util::Clock clk;
struct XXX {
~XXX()
{
printf("%.1f Mclk\n", clk.getClock() / double(clk.getCount()) * 1e-6);
Rprintf("%.1f Mclk\n", clk.getClock() / double(clk.getCount()) * 1e-6);
}
} xxx;
#endif
Expand Down Expand Up @@ -115,13 +115,13 @@ struct CipherParam {
}
void put() const
{
printf("cipherName = %s\n", cipherNameStr.c_str());
printf("saltSize = %d\n", (int)saltSize);
printf("blockSize = %d\n", (int)blockSize);
printf("keyBits = %d\n", (int)keyBits);
printf("hashName = %s\n", hashNameStr.c_str());
printf("hashSize = %d\n", hashSize);
printf("saltValue = "); dump(saltValue, false);
Rprintf("cipherName = %s\n", cipherNameStr.c_str());
Rprintf("saltSize = %d\n", (int)saltSize);
Rprintf("blockSize = %d\n", (int)blockSize);
Rprintf("keyBits = %d\n", (int)keyBits);
Rprintf("hashName = %s\n", hashNameStr.c_str());
Rprintf("hashSize = %d\n", hashSize);
Rprintf("saltValue = "); dump(saltValue, false);
}
explicit CipherParam(const cybozu::minixml::Node *node)
{
Expand Down Expand Up @@ -272,23 +272,23 @@ struct EncryptionInfo {
void put() const
{
if (!isDebug(0)) return;
printf("major = %d\n", major);
printf("minor = %d\n", minor);
printf("isStandardEncryption = %d\n", isStandardEncryption);
Rprintf("major = %d\n", major);
Rprintf("minor = %d\n", minor);
Rprintf("isStandardEncryption = %d\n", isStandardEncryption);
if (isStandardEncryption) {
seHeader.put();
seVerifier.put();
} else {
printf("spinCount = %d\n", spinCount);
puts("keyData");
Rprintf("spinCount = %d\n", spinCount);
Rprintf("keyData");
keyData.put();
printf("encryptedHmacKey = "); dump(encryptedHmacKey, false);
printf("encryptedHmacValue = "); dump(encryptedHmacValue, false);
puts("encryptedKey");
Rprintf("encryptedHmacKey = "); dump(encryptedHmacKey, false);
Rprintf("encryptedHmacValue = "); dump(encryptedHmacValue, false);
Rprintf("encryptedKey");
encryptedKey.put();
printf("encryptedVerifierHashInput = "); dump(encryptedVerifierHashInput, false);
printf("encryptedVerifierHashValue = "); dump(encryptedVerifierHashValue, false);
printf("encryptedKeyValue = "); dump(encryptedKeyValue, false);
Rprintf("encryptedVerifierHashInput = "); dump(encryptedVerifierHashInput, false);
Rprintf("encryptedVerifierHashValue = "); dump(encryptedVerifierHashValue, false);
Rprintf("encryptedKeyValue = "); dump(encryptedKeyValue, false);
}
}

Expand All @@ -311,7 +311,7 @@ struct EncryptionInfo {

p += encryptionHeaderSize;
dataSize -= encryptionHeaderSize;
printf("dataSize=%u\n", (uint32_t)dataSize);
Rprintf("dataSize=%u\n", (uint32_t)dataSize);
seVerifier.analyze(p, dataSize);
seVerifier.put();
}
Expand Down
10 changes: 5 additions & 5 deletions src/cryptography/msoc/include/decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ inline bool getAgileSecretKey(std::string& secretKey, const EncryptionInfo& info
const std::string skey3 = generateKey(encryptedKey, pwHash, ms::blkKey_encryptedKeyValue);
secretKey = cipher(encryptedKey.cipherName, info.encryptedKeyValue, skey3, iv, cybozu::crypto::Cipher::Decoding);
if (isDebug()) {
printf("salt = "); dump(keyData.saltValue, false);
printf("secretKey = "); dump(secretKey, false);
Rprintf("salt = "); dump(keyData.saltValue, false);
Rprintf("secretKey = "); dump(secretKey, false);
}
return true;
}
Expand All @@ -117,11 +117,11 @@ inline bool decodeAgile(std::string& decData, const std::string& encryptedPackag
if (secretKey.empty()) {
if (!getAgileSecretKey(secretKey, info, pass)) return false;
if (putSecretKeyInstance()) {
printf("secretKey = "); ms::dump(secretKey, false);
Rprintf("secretKey = "); ms::dump(secretKey, false);
}

if (!VerifyIntegrity(encryptedPackage, keyData, secretKey, keyData.saltValue, info.encryptedHmacKey, info.encryptedHmacValue)) {
printf("warning : mac err : data may be broken\n");
Rprintf("warning : mac err : data may be broken\n");
// return false;
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ inline bool decodeStandardEncryption(std::string& dec, const std::string& encryp
}
}
if (isDebug()) {
printf("secretKey = "); dump(secretKey, false);
Rprintf("secretKey = "); dump(secretKey, false);
}

const char *p = encryptedPackage.data();
Expand Down
10 changes: 5 additions & 5 deletions src/cryptography/msoc/include/encode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ inline void EncContent(std::string& encryptedPackage, const std::string& org, co
}

/*
これの逆順で暗号化
����̋t���ňÍ���
fix parameter : c1(blkKey_VerifierHashInput)
c2(blkKey_encryptedVerifierHashValue)
c3(blkKey_encryptedKeyValue)
Expand All @@ -107,20 +107,20 @@ output: iv,
encryptedVerifierHashValue,
encryptedKeyValue
iv(encryptedKey.saltValue)をランダム生成
iv(encryptedKey.saltValue)�������_������
pwHash = hashPassword(iv, pass, spinCount)
skey1 = generateKey(pwHash, c1)
skey2 = generateKey(pwHash, c2)
verifierHashInputをランダム生成
verifierHashInput�������_������
encryptedVerifierHashInput = Enc(verifierHashInput, skey1, iv)
hashedVerifier = H(verifierHashInput)
encryptedVerifierHashValue = Enc(verifierHash, skey2, iv)
skey3 = generateKey(pwHash, c3)
secretKeyをランダム生成
secretKey�������_������
encryptedKeyValue = Enc(secretKey, skey3, iv)
*/

Expand Down Expand Up @@ -150,7 +150,7 @@ inline bool encode_in(
std::string& iv = encryptedKey.saltValue;
FillRand(iv, encryptedKey.saltSize);
#ifdef SAME_KEY
puts("QQQ defined SAME_KEY QQQ");
Rprintf("QQQ defined SAME_KEY QQQ");
iv = fromHex("F4994F9B2DCD5E0E84BC6386D4523D2C");
#endif
const std::string pwHash = hashPassword(encryptedKey.hashName, iv, pass, spinCount);
Expand Down
6 changes: 3 additions & 3 deletions src/cryptography/msoc/include/make_dataspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ inline void makeDataSpace(
/7:Transformation/8:StrongEncryptionTransform/9:Primary(F)
<10:B>
^_
�^�_
<2:R> <1:R>
---------------
<4:B>
^_
�^�_
<3:B> <5:B>
_
_
<7:R>
---------------
<6:B>
Expand Down
Loading

0 comments on commit 19ec345

Please sign in to comment.