NULL, // #636
NULL, // #637
VM_CL_RotateMoves, // #638
-NULL, // #639
+VM_digest_hex, // #639
+NULL, // #640
};
const int vm_cl_numbuiltins = sizeof(vm_cl_builtins) / sizeof(prvm_builtin_t);
}
// end
+qboolean Crypto_Available(void)
+{
+ if(!d0_blind_id_dll)
+ return false;
+ return true;
+}
+
// keygen code
static void Crypto_KeyGen_Finished(int code, size_t length_received, unsigned char *buffer, void *cbdata)
{
void Crypto_Init(void);
void Crypto_Init_Commands(void);
void Crypto_Shutdown(void);
+qboolean Crypto_Available(void);
+void sha256(unsigned char *out, const unsigned char *in, int n); // may ONLY be called if Crypto_Available()
const void *Crypto_EncryptPacket(crypto_t *crypto, const void *data_src, size_t len_src, void *data_dst, size_t *len_dst, size_t len);
const void *Crypto_DecryptPacket(crypto_t *crypto, const void *data_src, size_t len_src, void *data_dst, size_t *len_dst, size_t len);
#define CRYPTO_NOMATCH 0 // process as usual (packet was not used)
//idea: motorsep, Spike
//DarkPlaces implementation: divVerent
//builtin definitions:
-string(string digest, string data, ...) digest_hex = #638;
+string(string digest, string data, ...) digest_hex = #639;
//description:
//returns a given hex digest of given data
-//digest is always encoded in hexadecimal
+//the returned digest is always encoded in hexadecimal
//only the "MD4" digest is always supported!
//if the given digest is not supported, string_null is returned
+//the digest string is matched case sensitively, use "MD4", not "md4"!
//DP_QC_DIGEST_SHA256
//idea: motorsep, Spike
//DP_SND_FAKETRACKS
//idea: requested
+
//darkplaces implementation: Elric
//description:
//the engine plays sound/cdtracks/track001.wav instead of cd track 1 and so on if found, this allows games and mods to have music tracks without using ambientsound.
"DP_QC_CRC16 "
"DP_QC_CVAR_TYPE "
"DP_QC_CVAR_DESCRIPTION "
+"DP_QC_DIGEST "
+"DP_QC_DIGEST_SHA256 "
"DP_QC_FINDCHAIN_TOFIELD "
"DP_QC_I18N "
"DP_QC_LOG "
VM_M_crypto_getencryptlevel, // #635 string(string addr) crypto_getencryptlevel
VM_M_crypto_getmykeyfp, // #636 string(float addr) crypto_getmykeyfp
VM_M_crypto_getmyidfp, // #637 string(float addr) crypto_getmyidfp
+NULL, // #638
+VM_digest_hex, // #639
NULL
};
return false;
#endif
}
+
+ // special sheck for d0_blind_id
+ if (!strcasecmp("DP_CRYPTO", name))
+ return Crypto_Available();
+ if (!strcasecmp("DP_QC_DIGEST_SHA256", name))
+ return Crypto_Available();
+
return true;
}
}
{
float insensitive;
static char s[VM_STRINGTEMP_LENGTH];
- VM_SAFEPARMCOUNTRANGE(2, 8, VM_hash);
+ VM_SAFEPARMCOUNTRANGE(2, 8, VM_crc16);
insensitive = PRVM_G_FLOAT(OFS_PARM0);
VM_VarString(1, s, sizeof(s));
PRVM_G_FLOAT(OFS_RETURN) = (unsigned short) ((insensitive ? CRC_Block_CaseInsensitive : CRC_Block) ((unsigned char *) s, strlen(s)));
}
+// #639 float(string digest, string data, ...) digest_hex
+void VM_digest_hex(void)
+{
+ const char *digest;
+
+ static char out[32];
+ static char outhex[65];
+ int outlen;
+
+ static char s[VM_STRINGTEMP_LENGTH];
+ int len;
+
+ VM_SAFEPARMCOUNTRANGE(2, 8, VM_digest_hex);
+ digest = PRVM_G_STRING(OFS_PARM0);
+ if(!digest)
+ digest = "";
+ VM_VarString(1, s, sizeof(s));
+ len = strlen(s);
+
+ outlen = 0;
+
+ if(!strcmp(digest, "MD4"))
+ {
+ outlen = 16;
+ mdfour(&out, s, len);
+ }
+ else if(!strcmp(digest, "SHA256") && Crypto_Available())
+ {
+ outlen = 32;
+ sha256(&out, s, len);
+ }
+ // no warning needed on mismatch - we return string_null to QC
+
+ if(outlen)
+ {
+ int i;
+ static const char *hexmap = "0123456789abcdef";
+ for(i = 0; i < outlen; ++i)
+ {
+ outhex[2*i] = hexmap[(out[i] >> 4) & 15];
+ outhex[2*i+1] = hexmap[(out[i] >> 0) & 15];
+ }
+ outhex[2*i] = 0;
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(outhex);
+ }
+ else
+ PRVM_G_INT(OFS_RETURN) = 0;
+}
+
void VM_wasfreed (void)
{
VM_SAFEPARMCOUNT(1, VM_wasfreed);
void VM_strireplace (void);
void VM_crc16(void);
+void VM_digest_hex(void);
void VM_SetTraceGlobals(const trace_t *trace);
void VM_ClearTraceGlobals(void);
"DP_QC_CVAR_DESCRIPTION "
"DP_QC_CVAR_STRING "
"DP_QC_CVAR_TYPE "
+"DP_QC_DIGEST "
+"DP_QC_DIGEST_SHA256 "
"DP_QC_EDICT_NUM "
"DP_QC_ENTITYDATA "
"DP_QC_ENTITYSTRING "
VM_getsurfacenumtriangles, // #628 float(entity e, float s) getsurfacenumpoints (DP_QC_GETSURFACETRIANGLE)
VM_getsurfacetriangle, // #629 vector(entity e, float s, float n) getsurfacepoint (DP_QC_GETSURFACETRIANGLE)
NULL, // #630
+NULL, // #631
+NULL, // #632
+NULL, // #633
+NULL, // #634
+NULL, // #635
+NULL, // #636
+NULL, // #637
+NULL, // #638
+VM_digest_hex, // #639
+NULL, // #640
};
const int vm_sv_numbuiltins = sizeof(vm_sv_builtins) / sizeof(prvm_builtin_t);