gpt4 book ai didi

node.js - 在 STUN 服务器上实现 XOR-MAPPED-ADDRESS 属性

转载 作者:太空宇宙 更新时间:2023-11-03 23:36:59 25 4
gpt4 key购买 nike

来自RFC 5389 Section 15.2 :

If the IPaddress family is IPv4, X-Address is computed by taking the mapped IPaddress in host byte order, XOR'ing it with the magic cookie, andconverting the result to network byte order. If the IP addressfamily is IPv6, X-Address is computed by taking the mapped IP addressin host byte order, XOR'ing it with the concatenation of the magiccookie and the 96-bit transaction ID, and converting the result tonetwork byte order.

我正在 Node.JS 中编写一个 STUN 服务器,我试图了解如何对 128 位值进行异或运算。我觉得好像需要使用 Buffer 中的这些函数之一模块,尽管它说最多只支持 48 位。关于如何为 IPv6 地址实现 128 位 XOR 运算符有什么建议吗?

最佳答案

这是我的 CryptoPals 代码中的 XOR 运算符:

var xor = function (b0, b1) {
if (Buffer.isBuffer(b0)) {
b0 = new Buffer(b0);
}
if (Buffer.isBuffer(b1)) {
b1 = new Buffer(b1);
}

if (b0.length !== b1.length) {
console.log(b0.length, b1.length);
throw new Error('Tried to xor two buffers of differing length');
}

var arr = [];

for (var i = 0; i < b0.length; i++) {
arr.push(b0[i] ^ b1[i]);
}

return new Buffer(arr);
};

关于node.js - 在 STUN 服务器上实现 XOR-MAPPED-ADDRESS 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30904407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com